[thelist] PHP - mysql_fetch_array

Rich Gray richardgray at onetel.co.uk
Thu Aug 1 05:16:00 CDT 2002


You'll need to reset the result pointer back to the start of the result
array...
Use  mysql_data_seek($countries, 0)  before you start the 2nd loop.

Rich
-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Peter Duchateau
Sent: 01 August 2002 11:07
To: thelist at lists.evolt.org
Subject: [thelist] PHP - mysql_fetch_array


I want to loop twice over the result of my sql query.
1) show all agents for North America
2) show all agents for South America

I never get any agents in the second loop ?

<?
// include database connection
require("../../../includes/db_connection.php");

$lang = "nl";

$sql = "select c.country_id, c.name_" .$lang . " as country, c.region_id " .
       "from agents a, countries c " .
       "where a.country_id = c.country_id " .
       "and a.duiven = 'Y' " .
       "group by c.country_id, c.name_" .$lang . " " .
       "order by c.region_id, c.name_" .$lang;
//echo $sql;
$countries = mysql_query($sql, $connection) or die("Error in query: " .
mysql_error());
?>
...

<table width="560" cellpadding="0" cellspacing="0" border="0">
<tr>
    <td valign="top">
        <table border="0" width="90">
        <tr><td bgcolor="#BB1717" class="continent">North America</td></tr>
        <? while ($myrow = mysql_fetch_array($countries)) {
            if ($myrow["region_id"] == 1) { ?>
        <tr><td class="landen"><a href="detail_land.php?country_id=<?=
$myrow["country_id"]; ?>"><?= $myrow["country"]; ?></a></td></tr>
        <? }
        } ?>
        </table>
    </td>
    <td valign="top">
        <table border="0" width="90">
        <tr><td bgcolor="#BB1717" class="continent">South America</td></tr>
        <? while ($myrow = mysql_fetch_array($countries)) {
            if ($myrow["region_id"] == 2) { ?>
        <tr><td class="landen"><a href="detail_land.php?country_id=<?=
$myrow["country_id"]; ?>"><?= $myrow["country"]; ?></a></td></tr>
        <? }
        } ?>
        </table>
    </td>
</tr>
</table>
...

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list