looping MySQL query result in PHP

$b = 1;
$d = mysql_query("select *from 'table_name'");
while($b < 10){
    while($e = mysql_fetch_array($d)){
        echo $e['name_field'];
    }
    $b++;
}

I want to loop the output, but I'm stuck. I've tried but still got nothing. something like this :

<?php
$a = 0; 
$b = 0;
for($a=0;$a<10;$a++){
    for($b=0;$b<10;$b++){
        echo $b;        
    }
}
This question and answers originated from www.stackoverflow.com
Question by (5/14/2011 12:28:43 PM)

Answer

Seperate * and FROM by a space. Use backticks or no delimiters instead of single quotes for the table name.

If you want to limit your result, add a LIMIT expression to your query:

SELECT * FROM `table_name` LIMIT 10

And then loop through the results:

while($row = mysql_fetch_array($d)){
     echo $row['name_field'];
}
Answer by

Find More Answers
Related Topics  php  mysql
Related Questions
  • mysql query result in php variable

    Is there any way to store mysql result in php variable? thanks $query = "SELECT username,userid FROM user WHERE username = 'admin' "; $result=$conn->query($query); then I want to print sel…
  • Query time result in MySQL w/ PHP

    Is there a way that I can get the time of a MySQL query (specifically with PHP)? The actual time it took to complete the query, that is. Something such as: Results 1 - 10 for brown. (0.11 seconds…
  • Looping through Array in PHP returned from MySQL Query

    I have a part of an application that loops through a return of a MySQL query (as we all know) in the form of an Array. However, I need several different format settings placed on some of the items r…
  • Query result in MySQL Console does not match the result of PHP's mysql_query()

    My MySQL query returns different results depending on how the query is submitted. When the query is submitted through the MySQL Console results in. mysql> SELECT `modx`.coverage_nation.id, …
  • PHP MYSQL query result "RANKING"

    I need to get a list of users Ranking by points and from my command line (MySQL) is was able to generate the necessary code: SET @rank=0; SELECT rank, iduser, pontos FROM ( SELECT @rank:=@rank+1 …
  • Search in array query result in php/mysql

    I have the mysql results ( $date_options ) as below Array ( [0] => stdClass Object ( [id] => 4 [start_date] => 2010-09-29 ) [1] => stdClass Object ( [id] => 13 …
  • MySQL query in PHP gives obvious wrong result

    I'm using PHP and PHPMyAdmin to create a small profile site. I'm giving members an ID number, based on which is the biggest number currently in the database, +1 I did 25 tests before I got the PH…
  • A question about query result judgement in PHP and MySQL

    Code as follows: $db = DatabaseService::getInstance(); //get a database handle,base on pdo $sql = "select * from authusers where ssouid = '".$ssouid."' order by regtime"; $res = $db->query($…
  • Put result from mysql_query in php array

    I want to get some results from the MySQL database and put them in a array like this: array("value2", "value2", "value3"); I have tried this: $models = array(); $getmodels = mysql_query("s…
  • MySQL/PHP - Query a result set?

    I have a result set that I want to filter. Question is how can I run a query on a result set? Using PHP and MySQL. Thanks