How do I loop through a PHP array containing data returned from MySQL?

后端 未结 6 1841
野趣味
野趣味 2020-12-21 18:10

Ok I have a table with a few fields. One of the fields is username. There are many times where the username is the same, for example:

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 18:40

    Use a loop, and use mysql_fetch_array() instead of row:

    while($row = mysql_fetch_array($result)) {
       echo "Study: " . $row[1] . " - " . $row[5];
       // but now with mysql_fetch_array() you can do this instead of the above
       // line (substitute userID and username with actual database column names)...
       echo "Study: " . $row["userID"] . " - " . $row["username"];
    }
    

提交回复
热议问题