php - table does not exists mysql but it does for loop -
i hava weired problem here mysql database , php.
in php, gets table names , loops through tables. takes rows , send variables function. using loops this.
the problem have 7 tables. if table 2 , 3 contain rows loops through 2 , correctly. , not give table not exists error table 1. table 3-7 gives table not exists.
but if remove rows in table 2 loops through 3 , works correctly, , gives no error 1 , 2. table 4-7 gives table not exists err. loops through 1 table rows , gives errors following tables. don't understand connection problem mysql or else.
below snippet of code:
<?php $hostname_localhost ="localhost"; $username_localhost ="xxxxxxx"; $password_localhost ="xxxxxxxxx"; $database_xxxxxxxxxx ="xxxxxxxxx"; $database_yyyyyyyyyyy ="yyyyyyyyyy"; $database_zzzzz = "zzzzz"; $localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),e_user_error); $get_all_tables = mysql_query("show tables xxxxxxxxx"); $table_names = array(); while($row = mysql_fetch_array($get_all_tables, mysql_num)) { array_push($table_names,$row[0]); } mysql_select_db($database_xxxxxxx, $localhost); ($i=0; $i<sizeof($table_names); $i++){ $table = trim($table_names[$i]); $get_tag = mysql_query("select * $table"); if ($get_tag){ while($get_tag_infos = mysql_fetch_array($get_tag)){ $similarity = $get_tag_infos['similarity']; //........... , many other variables if ($similarity == 20){ get20(many variables); } if ($similarity == 40){ get40(many variables); } if ($similarity == 60){ get60(many varibales); } if ($similarity == 80){ get80(many variables); } if ($similarity == 100){ get100(many variables); } } } else{ echo '</br> error! </br>'.mysql_error().mysql_errno(); } } function get20(many variables){ // performs insert function mysql } function get40(many variables){ // performs insert function mysql } function get60(many variables){ // performs insert function mysql } function get80(many variables){ // performs insert function mysql } function get100(many variables){ // performs insert function mysql } ?>
the problem connection database. after first table find connection has been changed inner connection. use different variables connections. setting code running perfectly. have tested.
<?php //conection: $link = mysqli_connect("localhost","root","pass","test") or die("error " . mysqli_error($link)); //consultation: $query = "show tables" or die("error in consult.." . mysqli_error($link)); //execute query. $result = mysqli_query($link, $query); //display information: while($row = mysqli_fetch_array($result)) { echo $row["tables_in_test"] . "<br>"; $link2 = mysqli_connect("localhost","root","pass","test") or die("error " . mysqli_error($link)); $query2 = "select * ".$row['tables_in_test'] or die("error in consult.." . mysqli_error($link2)); $result2 = mysqli_query($link2, $query2); while($row2 = mysqli_fetch_array($result2)) { echo "<pre>"; print_r($row2); echo "</pre>"; } } ?>
Comments
Post a Comment