About foreach output $ Sql1 = "select * from y_cate order by asc ";
$ Result1 = mysql_fetch_array (mysql_query ($ sql1 ));
Var_dump ($ result1 );
Foreach ($ result1 as $ ke => $ ){
Echo $ ."
";
}
?>
I want to use foreach to output all the data in the cate table cyclically. Why does it output only one piece of data? Answer
Reply to discussion (solution)
$sql1="select * from y_cate order by asc";$result1 = mysql_query($sql1);while($row = mysql_fetch_array($result1)) { foreach($row as $ke=>$a){ echo $a."
"; }}
$ Sql1 = "select * from y_cate order by asc ";
$ Result1 = mysql_fetch_array (mysql_query ($ sql1 ));
Var_dump ($ result1 );
Foreach ($ result1 as $ ke => $ ){
Echo $ ."
";
}
?>
I want to use foreach to output all the data in the cate table cyclically. Why does it output only one piece of data? 1. will your SQL statement return no error? Order by asc, no sorting field;
2. no SQL statement is executed. Mysql_query ($ sql1 ).
$ Sql1 = "select * from y_cate order by asc ";
$ Result1 = mysql_fetch_array (mysql_query ($ sql1 ));
Var_dump ($ result1 );
Foreach ($ result1 as $ ke => $ ){
Echo $ ."
";
}
?>
I want to use foreach to output all the data in the cate table cyclically. Why does it output only one piece of data? 1. will your SQL statement return no error? Order by asc, no sorting field;
2. no SQL statement is executed. Mysql_query ($ sql1). What is the incorrect hand?
Select * from y_cate order by asc
If no field is specified for order by, the following error occurs: #1064-You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "..........
$sql1="select * from y_cate order by asc";$result1 = mysql_query($sql1);while($row = mysql_fetch_array($result1)) { foreach($row as $ke=>$a){ echo $a."
"; }}
Must I use while?
If the while clause is used
[Code] $ sql1 = "select * from y_cate order by px asc ";
$ Us = mysql_query ($ sql1 );
While ($ result1 = mysql_fetch_array ($ us )){
Echo $ result1 ['name'];
} [/Code]
Isn't it more concise ?? And it seems that you will repeat the output in that method. below is the output data, repeat once.
43
43
Homepage
Homepage
50b5b9555f97e.png
50b5b9555f97e.png
0
0
0
0
Select * from y_cate order by asc
If no field is specified for order by, the following error occurs: #1064-You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near "..........
Dear user, the code of manual knock is Missing by mistake. How can I solve the problem?
$sql1="select * from y_cate order by asc";$result1 = mysql_query($sql1);while($row = mysql_fetch_array($result1)) { foreach($row as $ke=>$a){ echo $a."
"; }}
Must I use while?
If the while clause is used
[Code] $ sql1 = "select * from y_cate order by px asc ";
$ Us = mysql_query ($ sql1 );
While ($ result1 = mysql_fetch_array ($ us )){
Echo $ result1 ['name'];
} [/Code]
Isn't it more concise ?? And it seems that you will repeat the output in that method. below is the output data, repeat once.
43
43
Homepage
Homepage
50b5b9555f97e.png
50b5b9555f97e.png
0
0
0
0
Repeat is because you have replaced mysql_fetch_array with mysql_fetch_assoc without repeating it. for specific reasons, please refer to Baidu's two functions.
The method provided by maxcompute is correct. you need to output each item of each record. this is two loops. while takes each entry, foreach takes each entry. once you finish the change, you will loop through it. of course, you cannot meet your needs.
While ($ row = mysql_fetch_array ($ result1, MYSQL_ASSOC )){
Foreach ($ row as $ ke => $ ){
Echo $ ."
";
}
}
Or use mysql_fetch_assoc/mysql_fetch_row.