gpt4 book ai didi

php - 内部连接 ​​MySQL 查询的问题

转载 作者:行者123 更新时间:2023-11-29 00:12:38 25 4
gpt4 key购买 nike

我有以下 MySQL 内连接查询和 HTML 表。

表 1:daily_info表2:股票

连接是在两个表中都存在的名为“Symbol”的列上执行的。不幸的是,下面的 HTML 表格中没有生成任何数据。我错过了什么?

<?php
$query = "SELECT daily_info.Day, daily_info.Prev_close, stocks.Symbol, stocks.Company, stocks.Description FROM stocks INNER JOIN daily_info ON stocks.Symbol = daily_info.Symbol ORDER BY Day Desc";

$result = mysqli_query( $link, $query );


// All good?
if ( !$result ) {
// Nope
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die( $message );
}

?>
<br />
<hr />
<br />
<div id="table-wrapper">
<div id="table-scroll">
<table width="100%" style="text-align:center; vertical-align:middle'">
<thead><tr>
<th><span class="text">Company</span></th>
<th><span class="text">Symbol</span></th>
<th><span class="text">Previous Close</span></th>
</tr></thead>
<?php
while ( $row = mysqli_fetch_assoc($query) ) {
echo "<tr>";
echo "<td><a href=\"http://finance.yahoo.com/q?s=" . $row['Symbol'] . "\" target=\"_blank\">" . $row['Company'] . "</a></td>";
echo "<td><a href=\"http://finance.yahoo.com/q?s=" . $row['Symbol'] . "\" target=\"_blank\">" . $row['Symbol'] . "</a></td>";
echo "<td>" . $row['Prev_close'] . "</td>";
echo "</tr>";
}
?>
</table>

最佳答案

您在 $query 字符串上循环 -> $query = "SELECT daily_info.Day,...

<?php
while ( $row = mysqli_fetch_assoc($query) ) {
^^^^^^

你需要在 $result 资源上循环的地方 -> $result = mysqli_query( $link, $query );

<?php
while ( $row = mysqli_fetch_assoc($result) ) {
^^^^^^^

关于php - 内部连接 ​​MySQL 查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24338284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com