我有2个与此问题相关的表,它们被称为 satellite
和satellite_multi
。我为创建表的思维过程是卫星工作台中包括信道的CHANNEL_ID(主键),姓名及国指从通道播放,mysql/php - 基于ID查看数据库表中的特定行
satellite_multi table has a column called channelid_multi, which is linked as a
foreign key
to the channel_id from the satellite table, and the other columns are
SatName, Frequency, Polarisation, Symbrate, FEC, EncorFTA.
我创建了satellite_multi表,因为有一些多个卫星上的信道,例如Thor 0.8w和Hotbird 13.0e可能具有相同的频道广播,所以我需要一种能够显示多行数据的方式,如果频道在多个卫星上广播的话。
下面是satellite_multi表的表结构:
+-----------------+---------------+-----------+--------------+------------+-----+----------+
| ChannelID_Multi(FK) | SatName | Frequency | Polarisation | Symbrate | FEC | EncorFta |
+-----------------+---------------+-----------+--------------+------------+-----+----------+
| 1 | Thor 0.8w | 10932 | H | 275000 | 5/6 | ENC |
| 1 | Hotbird 13.0e | 10654 | V | 25000 | 3/4 | FTA |
+-----------------+---------------+-----------+--------------+------------+-----+----------+
This is the table structure for the table named satellite:
+-----------+----------------+----------+
| ChannelID (PK) | Name | Country |
+-----------+----------------+----------+
| 1 | Polsat Sport | Poland |
| 2 | Sky Sports | England |
+-----------+----------------+----------+
我有站点设置在用户点击的主要网站上的频道名称的超链接,他们被带到了一个名为页面view_channels .php,其中通道详细信息基于来自卫星表的频道ID显示。例如view_channel.php?channelid = 19
当通道位于一颗卫星上时,此功能正常工作,因为我可以运行SELECT *查询并显示所有数据。
我试图让多个通道数据显示在每个单独的通道ID下,但可悲的是它不起作用。
我用下面的下面的代码在我view_channels.php页
$sql = "SELECT s.name, s.country, f.satname, f.frequency, f.polarisation, f.symbrate, f.fec, f.encorfta
FROM satellitemulti f
LEFT JOIN satellite s
ON f.channelid_multi=s.channelid
GROUP BY s.name, s.country, f.satname, f.frequency, f.polarisation, f.symbrate, f.fec, f.encorfta";
$stmt = $DB->prepare($sql);
$stmt->execute();
的输出被示为全部来自satellite_multi表和卫星表中的信息为每一个信道ID,在该例子中,作为Polsat是ID 1,只显示polsat,但也显示包含不同ID的AFN Sports。 (见下图)
我的问题是,是不是我要添加到我的查询,以检查从浏览器链接的ID,并从表中收到的ID匹配,所以只有特定ID的频道数据才会显示?
我试图在添加一个WHERE子句,以显示基于channelid_multi
WHERE channelid_multi = $channelid_multi
数据,但我得到了一个错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN satellite s ON f.channelid_multi=s.channelid GROUP BY s.name, s.country, f.' at line 4' in E:\home\students\2132\B00614408\public_html\sportsschedule\view_channels.php:19 Stack trace: #0 E:\home\students\2132\B00614408\public_html\sportsschedule\view_channels.php(19): PDOStatement->execute() #1 {main} thrown in E:\home\students\2132\B00614408\public_html\sportsschedule\view_channels.php on line 19
感谢您的任何指导,任何人都可以提供
我已包括我的整个`
0下面
`代码的情况下,任何人都需要看那个
<?php
require_once './config.php';
include './header.php';
$sql = "SELECT s.name, s.country, f.satname, f.frequency, f.polarisation, f.symbrate, f.fec, f.encorfta
FROM satellitemulti f
WHERE channelid_multi = $channelid_multi
LEFT JOIN satellite s
ON f.channelid_multi=s.channelid
GROUP BY s.name, s.country, f.satname, f.frequency, f.polarisation, f.symbrate, f.fec, f.encorfta";
$stmt = $DB->prepare($sql);
$stmt->execute();
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"> Whats On</h3>
</div>
<div class="panel-body">
</div>
<div class="clearfix"></div>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered ">
<tbody>
<caption> Channel Details</caption>
<tr>
<th>Name</th>
<th>Country</th>
<th>Sat Name</th>
<th>Frequency</th>
<th>Polarisation</th>
<th>Symbol Rate</th>
<th>FEC</th>
<th>Enc or FTA</th>
</tr>
<?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$name = $row['name'];
$country= $row['country'];
$satname = $row['satname'];
$frequency=$row['frequency'];
$polarisation=$row['polarisation'];
$symbrate=$row['symbrate'];
$fec=$row['fec'];
$encorfta=$row['encorfta'];
$channelid_multi=$row['channelid_multi'];
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['satname'] . "</td>";
echo "<td>" . $row['frequency'] . "</td>";
echo "<td>" . $row['polarisation'] . "</td>";
echo "<td>" . $row['symbrate'] . "</td>";
echo "<td>" . $row['fec'] . "</td>";
echo "<td>" . $row['encorfta'] . "</td>";
}
echo "</tr>";
echo "</table>";
?>
</div>
<?php
include './footer.php';
?>
'$ sql =“SELECT s.name,s.country,f.satname,f.frequency,f.polarisation,f.symbrate,f.fec,f.encorfta FROM satellitemulti f LEFT JOIN卫星s ON f.channelid_multi = s.channelid WHERE channelid_multi = $ channelid_multi GROUP BY s.name,s.country,f.satname,f.frequency,f.polarisation,f.symbrate,f.fec,f.encorfta“ ;' –
是的,在哪里需要去左后加入和工作。 – nowhere
感谢您的帮助。我试着改变了上面所说的查询,但是我得到这个错误。 –