<?php // Create connection $con=mysqli_connect("localhost","root","root"); mysql_select_db("test") or die("Unable to select database"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //***************************** table 1 detail *********** $query = "SELECT * FROM fraud WHERE a_number=" . $_GET["aNun_id"]; echo "<title>" . $_GET["aNun_id"] . "</title>"; echo "<table width='50%' border='5'> <tr> <th>Date & Time</th> <th>A Number</th> <th>B Number</th> <th>Status</th> </tr>"; $result=mysql_query($query) or die (mysql_error()); while($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['a_number'] . "</td>"; echo "<td><a href='?bNun_id=".$row['b_number']."'>" . $row['b_number'] . "</a></td>"; echo "<td>" . $row['status'] . "</td>"; echo "</tr>"; } echo "</table>"; //***************************** table 2 detail *********** //Here i'm trying to use bNum_id in below query $query = "SELECT * FROM fraud WHERE b_number=" . $_GET["bNun_id"]; echo "<table width='50%' border='5'> <tr> <th>Date & Time</th> <th>A Number</th> <th>B Number</th> <th>Status</th> </tr>"; $result=mysql_query($query) or die (mysql_error()); while($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['a_number'] . "</td>"; echo "<td>" . $row['b_number'] . "</td>"; echo "<td>" . $row['status'] . "</td>"; echo "</tr>"; } echo "</table>"; //connection close mysqli_close($con); ?>
在這裏,我用aNun_id從與 「GET」 命令另一個PHP文件中獲取數據。 在表二中,我想要bNun_id在該表中顯示其相關數據。我如何將bNun _id數據從表1中的第二個表中調用。請幫助我..通話變量在PHP
**警告:**您的代碼對MySQL注入是開放的,您應該使用PDO/MySQLi與準備好的語句,或者在使用MySQL查詢之前正確清理您收到的數據。 – Prix
'$ _GET [「bNun_id」]' - 錯字? – 2014-02-09 09:53:05
同意@Prix。並且你有一個Nun_id而不是一個Num_id全部結束 – trainoasis