开发者

query not resolving right, how to?

开发者 https://www.devze.com 2023-03-22 00:26 出处:网络
i have a query that should return 40 results: $test = mysql_query(\" SELECT fname FROM online_all WHERE verify_status = \'v\' LIMIT 40 \");

i have a query that should return 40 results:

$test = mysql_query(" SELECT fname FROM online_all WHERE verify_status = 'v' LIMIT 40 ");
if (!$test ) {print " - Mysql Error - ";echo fns_et_mysql_error(mysql_error());}

if i echo mysql_num_rows($test); i get 40. which means that i get the results but when i print_r $roww = mysql_fetch_array($test); i get only one result.

there are no p开发者_Python百科hp errors.


You have to loop through the results with:

while($row = mysql_fetch_array($test)) {
    // awesomeness with $row
}


Try using a loop.

while($row = mysql_fetch_array($test)){

}


mysql_fetch_array returns one row at a time. If you want to loop through all of them you do the following:

while ($row = mysql_fetch_array($test))
    //Do something


http://php.net/manual/en/function.mysql-fetch-array.php

Check the documentation. mysql_fetch_array only fetches one row of data at a time. To get the data for all 40 rows you need a loop (like a for loop conditioned by mysql_num_rows).


You need to iterate the results from the query.

while($row = mysql_fetch_array($test))
{
  // This is how you print fname.
  echo $row[0];
}  

Please refer to the documentation where there's also many useful tips of how you can use this function.

http://php.net/manual/en/function.mysql-fetch-array.php

You should also know that there exist another useful function for fetching results from mysql queries that fetches results as an associative array.

http://php.net/manual/en/function.mysql-fetch-assoc.php


You have to loop thru the rows:

while($row = mysql_fetch_array($test)){
    var_dump($row);
    //etectera
}
0

精彩评论

暂无评论...
验证码 换一张
取 消