基本上我想要两个表,其中每个人都有Confirmed = 1,另一个表有Confirmed = 0.
我现在有这个SQL查询
$result = mysqli_query($con,"SELECT * FROM tbl_booking WHERE $row[Confirmed] = 1");
但我一直在
Notice: Undefined variable: row in C:\xampp\htdocs\test.php on line 19
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
该页面的其余代码
echo "<table border='1'>
<tr>
<th>ID</th>
<th>BookID</th>
<th>date</th>
<th>time</th>
<th>confirmed?</th>
</tr>";
while($row = mysqli_fetch_array($result) )
{ ?>
<tr>
<td> <?php echo $row['tbl_mem_id']; ?> </td>
<td> <?php echo $row['BookID']; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td> <?php echo $row['time']; ?> </td>
<td> <?php echo $row['Confirmed']; ?> </td>
<td> <a href=delete.php?BookID=<?php echo $row['BookID']; ?> </a> Delete </td>
<td>
<?php
if ($row['Confirmed'] == 0) { ?>
<a href=confirm.php?BookID=<?php echo $row['BookID']; ?> </a> Confirm </td> <?php } else { ?>
<a href=deny.php?BookID=<?php echo $row['BookID']; ?> </a> Deny </td> <?php
} ?>
</tr> <?php
} ?>
</table>
答案 0 :(得分:3)
您是否真的尝试将$row['Confirmed']
中的值放入查询中,还是只是尝试查询名为Confirmed
的字段?如果后者试试这个:
$result = mysqli_query($con,"SELECT * FROM tbl_booking WHERE Confirmed= 1");
但是你也似乎将php中的表与if ($row['Confirmed'] == 0)
区分开来,你可能需要在一个查询中获取所有数据:
$result = mysqli_query($con,"SELECT * FROM tbl_booking");
这不会像你最初要求的那样给你2张桌子。
你可以用这个创建2个html表:
<?php
$result = mysqli_query($con,"SELECT * FROM tbl_booking WHERE Confirmed = 1");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>BookID</th>
<th>date</th>
<th>time</th>
<th>confirmed?</th>
</tr>";
while($row = mysqli_fetch_array($result) )
{ ?>
<tr>
<td> <?php echo $row['tbl_mem_id']; ?> </td>
<td> <?php echo $row['BookID']; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td> <?php echo $row['time']; ?> </td>
<td> <?php echo $row['Confirmed']; ?> </td>
<td> <a href=delete.php?BookID=<?php echo $row['BookID']; ?> </a> Delete </td>
<td>
<a href=deny.php?BookID=<?php echo $row['BookID']; ?> </a> Deny </td>
</tr> <?php
} ?>
</table>
<?php
echo "<table border='1'>
<tr>
<th>ID</th>
<th>BookID</th>
<th>date</th>
<th>time</th>
<th>confirmed?</th>
</tr>";
$result = mysqli_query($con,"SELECT * FROM tbl_booking WHERE Confirmed = 0 ");
while($row = mysqli_fetch_array($result) )
{ ?>
<tr>
<td> <?php echo $row['tbl_mem_id']; ?> </td>
<td> <?php echo $row['BookID']; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td> <?php echo $row['time']; ?> </td>
<td> <?php echo $row['Confirmed']; ?> </td>
<td> <a href=delete.php?BookID=<?php echo $row['BookID']; ?> </a> Delete </td>
<td>
<a href=confirm.php?BookID=<?php echo $row['BookID']; ?> </a> Confirm </td>
</tr> <?php
} ?>
</table>