通过PHP mysql_fetch_array循环 [英] Looping through mysql_fetch_array in PHP
问题描述
所以,我有以下几点:
$ 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屋!