gpt4 book ai didi

php - 打破 while 循环并获取计数

转载 作者:行者123 更新时间:2023-11-29 02:55:26 32 4
gpt4 key购买 nike

我无法打破 while 循环。

<?php $quizsections = mysql_query("SELECT * FROM quiz_sections");
while($quizsectionsrslt = mysql_fetch_array($quizsections)){
$quizsectionsid = $quizsectionsrslt['id'];
$quizsectionsheading = $quizsectionsrslt['heading'];
$quizsectionsquizid = $quizsectionsrslt['quizid'];
$quizsectionsfirstslot = $quizsectionsrslt['firstslot'];
echo $quizsectionsheading."<br />";

$quizslots = mysql_query("SELECT * FROM quiz_slots WHERE `quizid`=$quizsectionsquizid");
while($quizslotsrslt = mysql_fetch_array($quizslots)){
$quizslotids = $quizslotsrslt['questionid'];
$questions = mysql_query("SELECT * FROM question WHERE `id`=$quizslotids");

while($questionsrslt = mysql_fetch_array($questions)){
echo $questiontext = $questionsrslt['id']."<br />";
}
}
}?>

它正在显示类似的输出

资质

1 2 3 .... 40

算术

1 2 3 ... 40

推理

1 2 3 ... 40

计算机

1 2 3 ... 40

但我想要的输出

资质

1 2 3 ... 10

算术

11 12 13 ... 25

推理

26 27 28 ... 30

计算机

31 32 33 ... 40

表结构

enter image description here

enter image description here

enter image description here

最佳答案

您将希望在 MySQL 查询上使用 LIMIT 以根据第一个槽更改输出

<?php $quizsections = mysql_query("SELECT * FROM quiz_sections");
while($quizsectionsrslt = mysql_fetch_array($quizsections)){
$quizsectionsid = $quizsectionsrslt['id'];
$quizsectionsheading = $quizsectionsrslt['heading'];
$quizsectionsquizid = $quizsectionsrslt['quizid'];
$quizsectionsfirstslot = $quizsectionsrslt['firstslot'];
echo $quizsectionsheading."<br />";

$quizslots = mysql_query("SELECT * FROM quiz_slots WHERE `quizid`=$quizsectionsquizid LIMIT ".($quizsectionsfirstslot-1).", 10");
while($quizslotsrslt = mysql_fetch_array($quizslots)){
$quizslotids = $quizslotsrslt['questionid'];
$questions = mysql_query("SELECT * FROM question WHERE `id`=$quizslotids");

while($questionsrslt = mysql_fetch_array($questions)){
echo $questiontext = $questionsrslt['id']."<br />";
}
}
}?>

关于php - 打破 while 循环并获取计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158988/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com