Jump to content

Loop through an Array


Bopo

Recommended Posts

Hi

 

Well basically I have a query which returns the first 50 records, and stores them within a mysql fetch array.

 

However I want to loop through each record and output the result into a table, however I am unsure on how I would do this, here's what I have so far:

 

result = mysql_query("SELECT * FROM cardata ORDER BY insurance_group ASC LIMIT 50");
$row = mysql_fetch_array($result);

 echo <<<MY_HTML

<table width="250" border="1">
<table summary="">
  <tr>
    <td>$row[model]</td>
    <td>$row[insurance_group]</td>
  </tr>
  <tr>
    <td>$row[model]</td>
    <td>$row[insurance_group]</td>
  </tr>
</table>
MY_HTML;

// 50 rows in total, just removed all of them for clarity
  

Link to comment
https://forums.phpfreaks.com/topic/136816-loop-through-an-array/
Share on other sites

result = mysql_query("SELECT * FROM cardata ORDER BY insurance_group ASC LIMIT 50");

echo "<table width=\"250\" border=\"1\">
<table summary=\"\">";

while ($row = mysql_fetch_array($result)) {
echo " <tr>
    <td>{$row['model']}</td>
    <td>{$row['insurance_group']}</td>
  </tr>";}
echo "</table>";

Ted

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.