Php 在第二个查询和嵌套结果中使用来自第一个mysqli查询的数据
我有多个表要在第二个查询的结果中使用,并将第二个结果嵌套在第一个结果中 我正在使用以下代码:Php 在第二个查询和嵌套结果中使用来自第一个mysqli查询的数据,php,mysql,mysqli,Php,Mysql,Mysqli,我有多个表要在第二个查询的结果中使用,并将第二个结果嵌套在第一个结果中 我正在使用以下代码: $result = mysqli_query($con,"SELECT info.lotto_id, info.name, info.number_balls, info.number_bonus_balls, info.db_name, country.name_eng AS country, currency.name AS currency, currency.symbol AS symbol,
$result = mysqli_query($con,"SELECT info.lotto_id, info.name, info.number_balls, info.number_bonus_balls, info.db_name, country.name_eng AS country, currency.name AS currency, currency.symbol AS symbol, next.draw_date AS next_draw, next.jackpot AS next_jackpot
FROM info
LEFT JOIN country ON info.country_id = country.id_country
LEFT JOIN currency ON info.currency_id = currency.currency_id
LEFT JOIN next ON info.lotto_id = next.lotto_id
WHERE (info.active='1')
ORDER BY next_jackpot DESC");
while($lotto = mysqli_fetch_array($result))
{
echo "<table border='0' width='600px' align='center'>";
echo "<tr>";
echo "<td>";
echo "<h1>Results for:</h1>";
echo "</td>";
echo "<td align='right'>";
echo "<p><img src='images/". $lotto['lotto_id'] ."_big.png' alt='". $lotto['name'] ." Results'/></p>";
echo "</td>";
echo "</tr>";
echo "</table>";
$result2 = mysqli_query($con,"SELECT * FROM" .$lotto['db_name'].
"ORDER BY date DESC
Limit 3");
while($draw = mysqli_fetch_array($result2))
{
echo "<table class='results' align='center'>";
echo "<tr>";
$draw['display_date'] = strtotime($draw['date']);
$lotto['cols'] = $lotto['number_balls'] + $lotto['number_bonus_balls'];
echo "<td class='date' colspan='".$lotto['cols']."'>".date('D M d, Y', $draw['display_date']). "</td>";
if ($draw[jp_code] < "1")
{
echo "<td class='winner' align='center'>Jackpot Amount</td>";
}
else
{
echo "<td class='rollover' align='center'>Rollover Amount</td>";
}
$result=mysqli\u query($con),“选择info.lotto\u id、info.name、info.number\u balls、info.number\u bonus\u balls、info.db\u name、country.name\u eng作为国家、currency.name作为货币、currency.symbol作为符号、next.draw\u日期作为下一次抽奖、next.jackpot作为下一次中奖
来自信息
左加入info.country\u id=country.id\u country上的国家
左连接info.currency\u id=currency.currency\u id上的货币
左下一步加入info.lotto\u id=next.lotto\u id
其中(info.active='1')
由下一个中奖者下单(说明);
while($lotto=mysqli\u fetch\u数组($result))
{
回声“;
回声“;
回声“;
echo“结果为:”;
回声“;
回声“;
回声“”;
回声“;
回声“;
回声“;
$result2=mysqli\u查询($con,“从“$lotto['db\u name]”中选择*)。
“按日期说明订购”
限额3”);
而($draw=mysqli\u fetch\u数组($result2))
{
回声“;
回声“;
$draw['display_date']=strotime($draw['date']);
$lotto['cols']=$lotto['number\u balls']+$lotto['number\u bonus\u balls'];
回显“.date('D,Y',$draw['display_date'])”;
如果($draw[jp_代码]<“1”)
{
回显“头奖金额”;
}
其他的
{
回显“滚动金额”;
}
它给了我以下错误:警告:mysqli_fetch_array()期望参数1是mysqli_result,布尔值在第59行的/home/content/95/11798395/html/results/info_mysqli.php中给出
这与我的results2查询有关。有人能告诉我我做错了什么吗
谢谢。更改:
$result2 = mysqli_query($con,"SELECT * FROM" .$lotto['db_name'].
"ORDER BY date DESC
Limit 3");
致:
我怀疑您需要在第二次查询中围绕表名添加空格。但是,通过检查
mysqli\u query()
的返回值,并查看mysqli\u error()
$result2 = mysqli_query($con, "SELECT * FROM {$lotto['db_name']} ORDER BY date DESC LIMIT 3");
if ($result === false) {
exit("Error: " . mysqli_error($con));
}