php - Inserts about 30 times MYSQL -


this php supposed insert "d2" based on if day selected in "d1". inserts 30 times each row in "d1". use while time , never run problem, idea why happen?

$query = mysqli_query($connection, 'select * '.$settings["d1"]);      while($query_array = mysqli_fetch_array($query)){        $connection_main = mysqli_connect($settings["hostname"], $settings["mysql_user"], $settings["mysql_pass"], 'u_db_main_'.$query_array['id']);     $dayofweek = strtolower(date('l'));     $query2 = mysqli_query($connection_main, 'select * '.$settings_main["d1"].' '.$dayofweek.' ="1"');   while($query2_array = mysqli_fetch_array($query2)){           mysqli_query($connection_main, "insert ".$settings_main["d2"]." (c1) value ('".$query2_array['data_1']."')");        $id = mysqli_insert_id($connection_main);        calc_function($id);   } } 

the function calc_function has no inserts in use global same variables, recalling insert?

function calc_function($id){    global $connection_main;    global $settings_main;    //rest of function below 

i have been working @ week , tested everything! appreciated!

your problem trying use same connection resource both fatch , insert. run query on connection lose previous results. use mysqli_fetch_all() of results $query2, itterate array , run insert query.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -