Matt
Matt

Reputation: 2509

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

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>';
 }

Upvotes: 0

Views: 442

Answers (2)

Ben
Ben

Reputation: 1535

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.

Upvotes: 2

Nahydrin
Nahydrin

Reputation: 13507

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>';

Upvotes: 1

Related Questions