我有3個獨立的MySQL查詢下面列出,有沒有結合他們這樣我就可以得到輸出相同,但只需一個電話到數據庫(而不是3)的MySQL調用數據庫減倍
由於任何方式提前
<?php
$host = '';
$dbUser = '';
$dbPass = '';
$db = '';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
$result = mysql_query("SELECT id,cat,extra1,bigimage FROM pp_photos WHERE extra1 = '120' ORDER BY rand() LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
print "<a href=\"http://www.\" target=\"_new\"> <img src=\"ng\" border=\"0\" ></a>";
}
?>
<?php
$host = '';
$dbUser = '';
$dbPass = '';
$db = '';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
$result = mysql_query("SELECT id,cat,extra1,bigimage FROM pp_photos WHERE extra1 = 'W599_PTO' ORDER BY rand() LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
print "<a href=\"php">[?]</FONT></a>";
}
?>
<?php
$host = '';
$dbUser = '';
$dbPass = '';
$db = '';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
$result = mysql_query("SELECT id,cat,extra1,extra5,bigimage FROM pp_photos WHERE extra5 = '120rear' ORDER BY rand() LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
print "<a href=\"09\" target=\"_new\"> <img src=\"http://pg\" border=\"0\" ert\"></a>";
}
?>
我現在編輯根據下面提供的幫助的代碼...我是在MySQL的新手和我不能確定如何使任何或所有3個圖像顯示根據設置的過濾器「額外1」字段的值...
<?php
$host = '';
$dbUser = '';
$dbPass = '';
$db = '';
mysql_connect("$host", "$dbUser", "$dbPass") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
$result = mysql_query("
SELECT extra1
FROM pp_photos
WHERE extra1 IN('1','10','12')
GROUP BY extra1")
or die(mysql_error());
while($row = mysql_fetch_array($result)) {
print "<a href=\"h3\" target=\"_new\"> images</a>";
}
?>
首先你不需要每次的mysql_connect的。其次,你實際上並沒有使用$ result的值。第三,'ORDER BY RAND()'速度非常慢。總而言之,你真的需要重新思考你想在這裏實現的目標。 – 2012-04-19 12:17:27