Questions about the foreach output

Source: Internet
Author: User
About the foreach output problem
$sql 1= "SELECT * from Y_cate ORDER by ASC";
$result 1=mysql_fetch_array (mysql_query ($sql 1));
Var_dump ($result 1);
foreach ($result 1 as $ke = = $a) {
echo $a. "
";
}
?>
I want to use foreach to loop through the output of all the data in the Cate table, why just output one piece of data? Ask for answers

Share to:


------Solution--------------------
$sql 1= "SELECT * from Y_cate ORDER by ASC";
$result 1 = mysql_query ($sql 1);
while ($row = mysql_fetch_array ($result 1)) {
foreach ($row as $ke = = $a) {
echo $a. "
";
}
}

------Solution--------------------
Reference:
$sql 1= "SELECT * from Y_cate ORDER by ASC";
$result 1=mysql_fetch_array (mysql_query ($sql 1));
Var_dump ($result 1);
foreach ($result 1 as $ke = = $a) {
echo $a. "
";
}
?>
I want to use foreach to loop through the output of all the data in the Cate table, why just output one piece of data? Ask for answers
1. Your SQL statement will not get an error? ORDER by ASC, no sort field;
2. No SQL statement executed. mysql_query ($sql 1).
------Solution--------------------
reference:
Quote: reference:
 $sql 1= "SELECT * from Y_cate ORDER by ASC"; 
$result 1 = mysql_query ($sql 1);
while ($row = mysql_fetch_array ($result 1)) {
foreach ($row as $ke = + $a) {
echo $a.
";
}
}

Do I have to use while?
If using while,
[code] $sql 1= "SELECT * from Y_cate ORDER by px ASC";
$US =mysql_query ($sql 1);
while ($result 1=mysql_fetch_array ($US)) {
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.