SQL query in a loop?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dkim777
Forum Newbie
Posts: 4
Joined: Mon Aug 31, 2009 3:31 pm

SQL query in a loop?

Post by dkim777 »

I'm trying to do mysql query in the loop but it only does it once.. any good right way to do this?
the loop itself is working it prints same number of echo statements in the loop as $ip_array array variable,
but it only queries once for that SQL query line.
should I used different loop? maybe while loop?
Thanks


foreach ($ip_array as $search) {
list($countryName) = mysql_fetch_row(mysql_query('SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$ip_array[$counter].'") AND c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1'));
echo " ----------";
echo $countryName;
echo " done";
echo "<BR>";
$counter++;
}
Post Reply