简体   繁体   中英

While Loop Iterating Once inside foreach loop php mysql

Below is my code:

foreach($to_list as $row)
{
    $query=mysql_query("SELECT * FROM `table_name` WHERE `name`='$row' LIMIT 1");
    while($rowx=mysql_fetch_array($query))
    {
        echo $row['name']."<br>";
    }
}

Foreach loop is iterating properly but while loop inside it is iterating only once. Some suggests that I can use array, but I tried to do so but error;

Output I m getting is(while loop iterating once):

John


Output I want is given below:

John

Hrithik

Salman

SELECT * FROM `table_name` WHERE `name`='$row' LIMIT 1

Selects exatly 1 row from table_name due to LIMIT 1 . Remove that bit, so it becomes

SELECT * FROM `table_name` WHERE `name`='$row'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM