I have a problem with my code. My objective is to fetch some data from database and update the database again.
while( $row = mysql_fetch_array($result) ) {
if ($phpgsb->doLookup($row['origin']) === true) {
echo var_dump($phpgsb->doLookup($row['origin'])). " - ". $row['origin'];
mysql_connect("localhost", "ali", "password");
mysql_query("UPDATE `mydatabase`.`dns_soa` SET active='N' WHERE origin='".$row['origin']."'");
echo "<br>";
}
}
the output of echo var_dump($phpgsb->doLookup($row['origin'])). " - ". $row['origin']; is
bool(true) - hello.com.
which is weird because if I remove mysql connect code
mysql_connect("localhost", "ali", "password");
mysql_query("UPDATE `mydatabase`.`dns_soa` SET active='N' WHERE origin='".$row['origin']."'");
the correct output from database will be shown:
bool(true) - hello.com.
bool(true) - jool.com.
bool(true) - kool.com.
Se everytime I ran this code only hello.com. record will be updated in database. This is wrong. How can I get all 3 records to be updated using my UPDATE query?
Thanks in advance.
Take this line:
and put it out (before) of the while loop. You don’t need to connect again and again to the db.