Jump to content

Looping through records(PHP, MYSQL)...


enrmpaga

Recommended Posts

Using mysql_result is a very long winded way of getting results (IMO). By using Thorpe's code you can do away with mysql_result and just use the $row array to access your results.

 

$query = 'SELECT * FROM table';
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result))
{
    // display contents of the $row array
    echo '<pre>' . print_r($row, true) . '</pre>';
}

To access a field from the row you'd use $row['field_name_here'] allows for much cleaner code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.