使用php将sql表输出为HTML

使用php将sql表输出为HTML,php,mysql,Php,Mysql,我需要我的php打印出一个HTML表格的所有天气报告和姓名和电子邮件的人。 这给了我一个错误 警告:mysqli_stmt::bind_result():绑定变量的数量与中prepared语句中的字段数量不匹配 这是我的密码 $query = "SELECT weather.report, cities.name, cities.email FROM weather INNER JOIN cities ON weather.city=cities.city "; $stmt = $mysq

我需要我的php打印出一个HTML表格的所有天气报告和姓名和电子邮件的人。 这给了我一个错误 警告:mysqli_stmt::bind_result():绑定变量的数量与中prepared语句中的字段数量不匹配

这是我的密码

$query = "SELECT weather.report,
 cities.name, cities.email FROM weather INNER JOIN cities ON weather.city=cities.city ";


$stmt = $mysqli->stmt_init();
if ($stmt->prepare($query)) {
    //$stmt->bind_param("s", $player); 
    $stmt->execute();
    $stmt->bind_result($tempCity, $tempReport, $tempName, $tempEmail); 
    echo "<table width=500 border=1 cellpadding=5>
            <tr><th>Temperature</th><th>Report</th><th>City</th><th>DATE</th></tr>";

    while ($stmt->fetch()) { 
        echo "<tr>
                <td>".$tempCity."</td>
                <td>".$tempReport."</td>
                <td>".$tempName."</td>
        <td>".$tempEmail."</td>
              </tr>\n";
    }
    echo "</table>";
    $stmt->close();
} else {
    $error = "Sorry could not retrieve information";  echo $error;  return;
}

$mysqli->close(); 
$query=“选择weather.report,
cities.name,cities.email FROM weather internal在weather.city=cities.city上加入cities”;
$stmt=$mysqli->stmt_init();
如果($stmt->prepare($query)){
//$stmt->bind_参数(“s”,$player);
$stmt->execute();
$stmt->bind_result($tempCity、$tempReport、$tempName、$tempEmail);
回声“
温度报告日期”;
而($stmt->fetch()){
回声“
“$tempCity。”
“$tempReport。”
“$tempName。”
“$tempEmail。”
\n”;
}
回声“;
$stmt->close();
}否则{
$error=“抱歉无法检索信息”echo$error;return;
}
$mysqli->close();

感谢您的帮助

实际上它是这么说的。您需要绑定查询中所选项目的确切数量。所以,从你的“选择”中报告、姓名、电子邮件……如果你只选择三个,那么绑定结果中只能有三个,你知道吗

$stmt->bind_result($tempCity, $tempReport, $tempName, $tempEmail); 
应该是

  $stmt->bind_result($tempReport, $tempName, $tempEmail); 

绑定也必须按照您选择它们的顺序。如果您翻转报表和城市,则绑定时报表数据将进入城市,反之亦然。请注意,您在select语句中提到了三个字段,并在bind_结果函数中传递了四个参数。因此,bind_结果在select中找不到第四个参数

从函数调用中删除一个参数 $stmt->bind_result($tempReport、$tempName、$tempEmail)


在select语句中添加city

字面意思是lol,您需要在查询中绑定所选项目。因此,报告、名称、电子邮件。如果您只绑定三个,那么绑定结果中只能有三个,您知道吗?如果您选择三个项目(报告、名称、电子邮件),则无法绑定四个结果:$tempCity、$tempReport、$tempName、$tempEmail(编辑:我自己注意:在给出与上面相同的答案之前刷新页面^^)@OldPadawan我完全想在添加答案后删除该评论haha@clearshot66:我不是唯一一个处于“cap'tain显而易见模式”->检查下面^^