简体   繁体   English

在第二个查询和嵌套结果中使用第一个mysqli查询中的数据

[英]Using data from first mysqli query in second query and nesting results

I have multiple tables I am joining to use in results for a second query and nesting the second results inside the first results. 我要加入多个表,以便在结果中使用第二个查询,并将第二个结果嵌套在第一个结果中。

I am using the following code: 我正在使用以下代码:

$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>";
} 

It is giving me the following error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/95/11798395/html/results/info_mysqli.php on line 59 它给了我以下错误:警告:mysqli_fetch_array()期望参数1为mysqli_result,在第59行的/home/content/95/11798395/html/results/info_mysqli.php中给出的布尔值

This relates to my results2 query. 这与我的results2查询有关。 Can somebody please suggest what I am doing wrong. 有人可以建议我做错了吗。

Thank you. 谢谢。

Change: 更改:

$result2 = mysqli_query($con,"SELECT * FROM" .$lotto['db_name'].
"ORDER BY date DESC
Limit 3");

to: 至:

$result2 = mysqli_query($con, "SELECT * FROM {$lotto['db_name']} ORDER BY date DESC LIMIT 3");
if ($result === false) {
    exit("Error: " . mysqli_error($con));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM