我有下面列出的 3 个单独的 MySQL 查询,有什么方法可以组合它们,这样我就可以获得相同的输出,但只需调用一次数据库(而不是 3 个)
提前致谢
<?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 的新手,我不确定如何设置过滤器,以便根据“额外 1”字段的值显示任何或所有 3 张图像...
<?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>";
}
?>