0
我hava在這裏與mysql數據庫和PHP weiring問題。表不存在mysql,但它爲循環
在PHP中,它獲取表名,然後循環遍歷表。獲取行,然後將變量發送給函數。我正在使用循環來做到這一點。
問題是我有7個表。如果表2和表3包含行,則它循環遍歷2並正確執行所有操作。並且它不會給表1中的表不存在錯誤,但是對於表3-7,它給出所有表,因爲表不存在。
但是,如果我刪除表2中的行,然後它循環通過3,並正常工作,並沒有給1和2的錯誤,但對於表4-7它給表不存在錯誤。 基本上它只通過一個表格循環,併爲所有後續表格提供錯誤。我不明白的是,連接問題到MySQL或其他東西。
下面是我的代碼片段:
<?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 FROM 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);
for ($i=0; $i<sizeof($table_names); $i++){
$table = trim($table_names[$i]);
$get_tag = mysql_query("SELECT * FROM $table");
if ($get_tag){
while($get_tag_infos = mysql_fetch_array($get_tag)){
$similarity = $get_tag_infos['similarity'];
//........... and 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 a insert function to mysql
}
function get40(many variables){
// performs a insert function to mysql
}
function get60(many variables){
// performs a insert function to mysql
}
function get80(many variables){
// performs a insert function to mysql
}
function get100(many variables){
// performs a insert function to mysql
}
?>
謝謝......忘了那個。其始終存在的小錯誤。 –