谢谢大家,问题已回答!如果有人有兴趣,更新的功能如下,所有其他代码保持不变:PHP Array问题 - 无法通过foreach循环使用
function fetch_questions($page) {
global $link;
$proc = mysqli_prepare($link, "SELECT * FROM tquestions_cwh WHERE page = ?");
mysqli_stmt_bind_param($proc, "i", $page);
mysqli_stmt_execute($proc);
$rowq = array();
stmt_bind_assoc($proc, $rowq);
// loop through all result rows
// while ($proc->fetch()) {
// print_r($rowq);
// $rows[]=$rowq;
// }
while ($proc->fetch())
{
foreach($rowq as $key=>$value)
{
$row_tmb[ $key ] = $value;
}
$rows[] = $row_tmb;
}
mysqli_stmt_close($proc);
mysqli_clean_connection($link);
return($rows);
}
好吧,
下面是代码:
function fetch_questions($page) {
global $link;
$proc = mysqli_prepare($link, "SELECT * FROM tquestions_cwh WHERE page = ?");
mysqli_stmt_bind_param($proc, "i", $page);
mysqli_stmt_execute($proc);
$rows = array();
stmt_bind_assoc($proc, $rowq);
// loop through all result rows
while ($proc->fetch()) {
// print_r($rowq);
$rows[]=$rowq;
}
mysqli_stmt_close($proc);
mysqli_clean_connection($link);
return($rows);
}
我然后将其添加到php变量,如下所示:
$qs = fetch_questions($page);
我然后依次通过的,就像这样:
foreach($qs as $value){
echo "<tr>".$value['qnum']." is the questions number and the question text is ".$value['qtext'].". The page and q values are ".$value['page']." and ".$value['questions']." respectively.</tr>";
输出,但是是这样的:
8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.
这不是我想要的东西,以供参考,使用打印功能看起来数组像这样:
Array
(
[0] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[1] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[2] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[3] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[4] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[5] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[6] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
[7] => Array
(
[questions] => q8
[qnum] => 8
[qtext] => I know how what I do fits into my team's objectives
[page] => 1
)
)
很明显,它没有循环显示每一行,因为它应该...任何建议?
荷马。
数据库中那些实际的8个条目是什么? – macbirdie 2010-04-24 08:31:28
好奇,请问您可以使用以下命令添加$ qs数组的转储:echo var_export($ qs,true)? – Cesar 2010-04-24 08:34:35
请提供您的需求清楚 – Karthik 2010-04-24 08:39:40