在 PHP 中循环遍历 mysql_fetch_array [英] Looping through mysql_fetch_array in PHP

查看:31
本文介绍了在 PHP 中循环遍历 mysql_fetch_array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下几点:

$i = 0;
$records = mysql_num_rows($sections_query);
$row_sections = mysql_fetch_array($sections_query);
    foreach ($row_sections as $value) {
    echo $value . "<br />";
}

执行后$records的值变为4,DB每行有2列.第一列值为section_id",第二列值为section_name".

The value of $records becomes 4 after execution and the DB has 2 columns per row. The first column value is 'section_id' and the second is 'section_name'.

我想写一个循环来打印'section_name'的值,比如-

I want to write a loop that will print out the value of 'section_name' like-

echo "<h3>" . $row_sections[section_name]; . "</h3>";

在循环中,所以基本上我将有 3 个 h3,每个 h3 包含 'section_name' 中的 4 个不同值

within the loop, so basically I'll have 3 h3's each containing the 4 different values in 'section_name'

也许 foreach() 不是最好的循环?反正我很迷茫.

And maybe foreach() isn't the best loop to use? Anyway, I'm confused.

希望这是有道理的,并提前感谢您的帮助!

Hope that makes sense, and thanks in advance for the help!

推荐答案

$i = 0;
$records = mysql_num_rows($sections_query);
while($row_sections = mysql_fetch_array($sections_query))
{
    echo "<h3>" . $row_sections['section_name'] . "</h3>";
}

这将遍历每一行并打印部分名称.

That will go through each row and print the Section Name.

这篇关于在 PHP 中循环遍历 mysql_fetch_array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆