所以我有以下内容:
$i = 0;
$records = mysql_num_rows($sections_query);
$row_sections = mysql_fetch_array($sections_query);
foreach ($row_sections as $value) {
echo $value . "
";
}
执行后$record的值变为4,DB每行有2列.第一列值为’section_id’,第二列为’section_name’.
我想写一个循环,打印出’section_name’的值,就像 –
echo "
" . $row_sections[section_name]; . "
";在循环中,基本上我将有3个h3,每个包含’section_name’中的4个不同值
也许foreach()不是最好的循环使用?无论如何,我很困惑.
希望有意义,并提前感谢您的帮助!
解决方法:
$i = 0;
$records = mysql_num_rows($sections_query);
while($row_sections = mysql_fetch_array($sections_query))
{
echo "
" . $row_sections['section_name'] . "
";}
这将遍历每一行并打印部分名称.
标签:php,arrays,mysql,loops
来源: https://codeday.me/bug/20190929/1832829.html