开发者

Fetch records of a table as an array php mySQL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

The query is:

How can I fetch the abbr from manualtab into an array. Code:

 $connection = mysql_connect('localhost', 'root', '') or di开发者_JAVA技巧e ('Unable to connect!');
 mysql_select_db('mydb') or die ('Unable to select database!');
 $query = 'SELECT abbr FROM manualtab';
 $result = mysql_query($query) or die ('Error in query');
 $row = mysql_fetch_row($result);


$array = array();
while ($row = mysql_fetch_row($result))
{
  $array[] = $row;
}


If you mean, fetching every abbr in an array, then:

$abbr = array();
while ($row = mysql_fetch_row($result))
{
    $abbr[] = $row[0];
}

is a way to do it.


That does the job, unless you want to fetch all values, in which case you'll need to loop:

 $connection = mysql_connect('localhost', 'root', '') or die ('Unable to connect!');
 mysql_select_db('mydb') or die ('Unable to select database!');
 $query = 'SELECT abbr FROM manualtab';
 $result = mysql_query($query) or die ('Error in query');
 $row_list = array();
 while($row = mysql_fetch_assoc($result)) {
   $row_list[] = $row;
 }

 var_dump($row_list);
     /* row_list now contains:
     array(
        array( 'abbr' => ... ),
        array( 'abbr' => ... ),
        array( 'abbr' => ... ),
            ...
     ) */
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜