SQL query in a loop?
Posted: Mon Aug 31, 2009 3:35 pm
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++;
}
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++;
}