MySQL fetching the first row instead of all

This problem normally occurs when your forgetting to place array into container, for example PHP

$query = mysql_query( "SELECT * FROM `table`" );
$getrows = mysql_fetch_assoc( $query );
 
foreach ( $getrows as $row ) {
echo $row['id'];
}

We will have in this situation only first row not others, to get all rows we must use while() loop PHP

$query = $db->query( "SELECT * FROM `matches`" );
while ( $rows = mysql_fetch_array( $query ) ) {
echo rows['id'];
}

using while loop your getting all rows you can save them into array and so on.

Leave a Reply

Your email address will not be published.