gpt4 book ai didi

php - 获取表的结果 Mysql left join

转载 作者:行者123 更新时间:2023-11-30 21:54:00 25 4
gpt4 key购买 nike

所以我想要的是以下内容。我有 3 个表:首先我会用英语解释我想要的最终结果:

让我用英文解释一下:

表 1 是 REGISTERED_MEMBERS

表2是公开课

表 3 我想要谁申请了以及他们申请了哪个类(class),并在从下拉列表中选择日期时在表格中显示!

最后应该是这样的: enter image description here

  1. table = razpisani_tecaji with (ID_TECAJA, DATE, STATUS, ST_ODPRTIH_MEST) enter image description here

  2. table = registrirani_clani wtih (ID_TECAJNIKA,IME,PRIIMEK, EMAIL) enter image description here

  3. table = prijave_na_tecaj with (ID_TECAJNIKA, ID_TECAJA, PLACILO)

enter image description here

现在在 HTML 中,我有一个下拉列表,其中填充了表 1 中的日期(这工作正常)。

    <form>
<select name="dates" onchange="showUser(this.value)">
<option value="" selected="selected">Izberi datum za pregled</option>;
<?php
$con = mysqli_connect('localhost','root','','viverius_education');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
$sql = mysqli_query($con, "SELECT ID_TECAJA, DATUM FROM razpisani_tecaji");
while ($row = $sql->fetch_assoc()){
echo "<option value='" . $row['ID_TECAJA'] . "'>" . $row['DATUM'] . "</option>";

}
?>

这里将一个 ID 保存到一个变量 q 中,然后通过 JS 将其发送到 php。这一切都有效。现在我想让用户选择一个日期并从 3. 表中获取结果,仅显示链接到 ID_TECAJNIKA 的 IME 和链接到 ID_TECAJNIKA 的 PLACILO。

到目前为止,这是我在 PHP 中所拥有的:

<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','viverius_education');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}

$sql="SELECT razpisani_tecaji.ID_TECAJA, registrirani_clani._ID_TECAJNIKA FROM prijave_na_tecaj
LEFT JOIN razpisani_tecaji ON prijave_na_tecaj.ID_TECAJA = razpisani_tecaji.ID_TECAJA
LEFT JOIN registrirani_clani ON prijave_na_tecaj.ID_TECAJNIKA = registrirani_clani.ID_TECAJNIKA";

$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>Ime</th>
<th>Placilo</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['ID_TECAJNIKA'] . "</td>";
echo "<td>" . $row['PLACILO'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>

最佳答案

$sql="选择 registrirani_clani., prijave_na_tecaj.,razpisani_tecaji.*来自 registrirani_clanileft join prijave_na_tecaj on registrirani_clani.ID_TECAJNIKA = prijave_na_tecaj.ID_TECAJNIKA左加入 razpisani_tecaji ON razpisani_tecaji.ID_TECAJA = prijave_na_tecaj.ID_TECAJA其中 razpisani_tecaji.ID_TECAJA = '".$q."'";

关于php - 获取表的结果 Mysql left join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46014700/

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