如何执行PHP中的边库存程序中的select查询如果有多行发生?
如何执行select query
里面存储过程在php mysql如果出现多行?如何执行PHP中的边库存程序中的select查询如果有多行发生?
首先我想从特定学生
那么a table (practice_test_result)
取distinct (chapter_id)
代表该distinct(chapter_id)
运行多一个查询的生成关联数组
我现在面临的问题是:
while(row found){ /* here i perform the SELECT SUM(total_question) - SUM(total_incomplete) , SUM(total_correct) into totalattempt,talcorrect FROM practice_test_summary WHERE student_id =studentid AND chapter_id =chapterid;
set chpapter_successrate[i] =(totalcorrect * 100)/totalattempt; */
}
下面的代码为更多关于问题我想要什么
DELIMITER // DROP PROCEDURE IF EXISTS get_result//
CREATE PROCEDURE get_result(studentid INT,courseid INT,out chpapter_successrate decimal(10,2))
BEGIN
SELECT distinct(chapter_id) FROM practice_test_result WHERE course_id =courseid AND student_id =studentid;
set chapterid=chapter_id;
//here i want to use while loop for all chapter_id and behalf of these chpater id's perform another select statement for performing successrate of specific chapter and store that into an array and return that array as out variable
SELECT SUM(total_question) - SUM(total_incomplete) , SUM(total_correct) into totalattempt,talcorrect FROM practice_test_summary WHERE student_id =studentid AND chapter_id =chapterid;
set chpapter_successrate[i] =(totalcorrect * 100)/totalattempt;
END//
回答:
你想用来生成你的while循环的功能是一个MySQL的“光标”。
然后,您可以将每个chapter_id“提取”为一个局部变量,以便在第二个select语句中使用。
这是mysql文档的一个链接和一个很好的例子。
http://dev.mysql.com/doc/refman/5.0/en/cursors.html
你需要修改以上为本地chapterid变量声明语句。
此外,您将无法将chpapter_successrate [i]用作MySQL存储过程中的数组。请参阅:How can I simulate an array variable in MySQL?替代品。也许临时表是一个很好的解决方法。
以上是 如何执行PHP中的边库存程序中的select查询如果有多行发生? 的全部内容, 来源链接: utcz.com/qa/266315.html