通过PHP mysql_fetch_array循环 [英] Looping through mysql_fetch_array in PHP

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

问题描述

所以,我有以下几点:

  $ I = 0;
$记录= mysql_num_rows($ sections_query);
$ row_sections = mysql_fetch_array($ sections_query);
    的foreach($ row_sections为$值){
    回声$价值。 < BR />中;
}

$的记录值执行后变为4和DB有每行2列。第一列的值是'SECTION_ID'和第二是SECTION_NAME'

我想写一个循环,将打印出像'SECTION_NAME'的价值 -

 回声< H3>中。 $ row_sections [SECTION_NAME] 。 &所述; / H3>中;

在循环中,所以基本上我将有3 H3的每个包含在SECTION_NAME

4个不同的值

和可能的foreach()不使用最好的循环?无论如何,我很困惑。

希望是有道理的,并在此先感谢您的帮助!


解决方案

  $ I = 0;
$记录= mysql_num_rows($ sections_query);
而($ row_sections = mysql_fetch_array($ sections_query))
{
    回声< H3>中。 $ row_sections ['SECTION_NAME']。 &所述; / H3>中;
}

这将通过每一行和打印的部分名称。

So I have the following:

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

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'.

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

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

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

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天全站免登陆