的結果不匹配我的MySQL查詢根據查詢的提交方式返回不同的結果。當查詢當同樣的查詢使用提交通過MySQL控制檯結果。MySQL控制檯中的查詢結果與PHP的mysql_query()
mysql> SELECT `modx`.coverage_nation.id,
-> `modx`.coverage_nation.name,
-> `modx`.coverage_national_region.id,
-> `modx`.coverage_national_region.name
-> FROM `modx`.coverage_nation_part
-> RIGHT JOIN `modx`.coverage_national_region ON (`modx`.coverage_nati
on_part.nation_regionID = `modx`.coverage_national_region.id)
-> RIGHT JOIN `modx`.coverage_nation ON (`modx`.coverage_nation_part.n
ationID = `modx`.coverage_nation.id)
-> ORDER BY `modx`.coverage_nation.name ASC, `modx`.coverage_national_region
.name ASC;
+----+---------------+------+------+
| id | name | id | name |
+----+---------------+------+------+
| 3 | Canada | NULL | NULL |
| 18 | Chad | NULL | NULL |
| 17 | Germany | NULL | NULL |
| 15 | Italy | NULL | NULL |
| 2 | Mexico | NULL | NULL |
| 19 | Nigeria | NULL | NULL |
| 14 | Russia | NULL | NULL |
| 16 | Spain | NULL | NULL |
| 1 | United States | NULL | NULL |
+----+---------------+------+------+
9 rows in set (0.00 sec)
提交PHP的mysql_query
它返回只有一行。
$query .= "SELECT `modx`.coverage_nation.id,
`modx`.coverage_nation.name,
`modx`.coverage_national_region.id,
`modx`.coverage_national_region.name
FROM `modx`.coverage_nation_part
RIGHT JOIN `modx`.coverage_national_region ON (`modx`.coverage_nation_part.nation_regionID = `modx`.coverage_national_region.id)
RIGHT JOIN `modx`.coverage_nation ON (`modx`.coverage_nation_part.nationID = `modx`.coverage_nation.id)
ORDER BY `modx`.coverage_nation.name ASC, `modx`.coverage_national_region.name ASC;";
$resultSet = mysql_query($query) or die("query failed ".mysql_error());
while($row = mysql_fetch_array($resultSet,MYSQL_NUM)) {
// handle each result here
}
只返回加拿大。有沒有人有任何想法可以解決這個問題?
相同的查詢通常會導致相同的結果。 (除非有非常奇怪的觀點和用戶權限在繼續)更有可能的是,PHP代碼處理它時有一個小錯誤,謹慎發佈? – Wrikken 2010-09-20 17:11:56
如果您覺得有幫助,可以在https://docs.google.com/leaf?id=0B2rZ59SOyaKmOWIxZTlhMGItYjVmNi00MDRkLWFjZjctODE2NDM3YzkwMWFi&hl=en&authkey=CPqy7Y4D上找到完整代碼。查詢在第一個文件中提交,結果在第二個文件中處理。 https://docs.google.com/leaf?id=0B2rZ59SOyaKmZDZjYzI2Y2EtMmFiZS00NjQyLTliZWQtMWQ3Y2VkNWZhMDY5&hl=en&authkey=CP3S5_4C – 2010-09-21 14:14:01
等待。您發佈的代碼與正在運行的代碼不同,而是與您認爲正在運行的代碼相加。 – webbiedave 2010-09-21 19:21:52