开发者

why can't I see the full array of my mysql data for php?

开发者 https://www.devze.com 2023-03-18 01:34 出处:网络
I have a question about this .... $query = \'SELECT * FROM EXAMPLE\'; $result = mysql_query($query); $row = mysql_fetch_array ($result);

I have a question about this ....

$query = 'SELECT * 
            FROM EXAMPLE';
$result = mysql_query($query);
$row = mysql_fetch_array ($result);
print_r($row开发者_运维百科);

This has the data of the first row [0] => 1 [id]=> 1... blah, blah but now I'm just wondering, what about the other table data? Is it a php safety to not display the "full array" of all the data inside EXAMPLE table? Just the first row of the data?

This is just out of curiosity.

I know if I want to see specific part of the entire data I can do a while loop.

 while ($row = mysql_fetch_array ($result)) {
   echo $row['text'].'<br>';
 }


mysql_fetch_array only returns one row of data. In your second example you are calling mysql_fetch_array over and over for every row.


To output all your data, do the following:

$query = 'SELECT * FROM EXAMPLE';
$result = mysql_query( $query );
print( '<pre>' ); // Preserve Whitespace/Newlines

while ( $row = mysql_fetch_array( $result ) )
    print_r($row);

print( '</pre>' );

If you want to see a specific part of the entire data, do the following:

while ( $row = mysql_fetch_assoc( $result ) )
    echo $row['text'].'<br>';
0

精彩评论

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

关注公众号