gpt4 book ai didi

PHP 结果没有获取 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-29 03:16:02 25 4
gpt4 key购买 nike

我不懂 PHP 和 SQL。我们只是在学期末才勉强把它刮掉,这让我很沮丧。我试图让我的结果页面显示正确的信息,但对于我来说,它不会抓取任何东西。我显然有问题,想知道是否可以得到一些帮助。

初始页

(这里是基本网页的正常顶部)

    <form id="ClubForm" action="ClubMembersResults.php" method="get">

<?php
require_once ('dbtest.php');
$query= "SELECT * FROM tblMembers ORDER BY LastName, FirstName, MiddleName;";
$r = mysqli_query($dbc, $query);
if (mysqli_num_rows($r) > 0) {
echo '<select id="memberid" name="memberid">';
while ($row = mysqli_fetch_array($r)) {
echo '<option value="'.$row['LastName'].'">'
.$row['LastName'].", ".$row['FirstName']." ".$row['MiddleName']. '</option>';
}
echo '</select>';
} else {
echo "<p>No Members found!</p>";
}
?>
<input type="submit" name="go" id="go" value="Go" />
</form>
<div id="results"></div>
</body>

结果页面当前写为:

<?php
$memid = 0;
$memid = (int)$_GET['memberid'];
if ($memid > 0) {

require_once ('dbtest.php');
$query = "SELECT * FROM tblMembers WHERE MemID = $memid;";
$r = mysqli_query($dbc, $query);`enter code here`
if (mysqli_num_rows($r) > 0) {
$row = mysqli_fetch_array($r);
echo "<p>Member ID: ".$row['MemID']."<br>";
echo "Member Name: ".$row['LastName'].", ".$row['FirstName']." ".$row['MiddleName']."<br>";
echo "Member Joined: ".$row['MemDt']."<br>";
echo "Member Status: ".$row['Status']."<br></p>";
}else {
echo "<p>Member not on file.</p>";
}
//table for inverntory
echo "<table border='1'>";
echo "<caption>Transaction History</caption>";
echo "<tr>";
echo "<th>Purchase Dt</th>";
echo "<th>Trans Cd</th>";
echo "<th>Trans Desc</th>";
echo "<th>Trans Type</th>";
echo "<th>Amount</th>";
echo "</tr>";
$query2 = "SELECT p.Memid, p.PurchaseDt, p.TransCd, c.TransDesc, p.TransType, p.Amount
FROM tblpurchases p, tblcodes c
WHERE p.TransCd = c.TransCd AND p.MemId = 'member id'
ORDER BY p.MemId, p.PurchaseDt, p.TransCd
";
$r2 = mysqli_query($dbc, $query2);
while ($row = mysqli_fetch_array($r2)) {
echo "<tr>";
echo "<td>".$row['PurchaseDt']."</td>;";
echo "<td>".$row['TransCd']."</td>";
echo "<td>".$row['TransDesc']."</td>";
echo "<td>".$row['TransType']."</td>";
echo "<td>".$row['Amount']."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo '<p>No Member ID from form.</p>';
}
?>

结果页面应该显示带有 TH 和 TR/TD 区域信息的表格。这两个区域都来自单独的 SQL 表,并且 tblmembers 和 tblpurchases 之间唯一相似的字段是 MemID。

最佳答案

您需要在 sql 请求中使用 join 来显示成员(member)的购买情况。

  SELECT m.Memid, p.PurchaseDt, p.TransCd, 

FROM tblpurchases p join
tblmembers m on p.MemId=m.MemId

这是一个连接的例子

关于PHP 结果没有获取 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56140259/

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