[英]view record using id
i can view the list of the users but when i'm trying to view the user record using their id, the output from the database doesn't show. 我可以查看用户列表,但是当我尝试使用其ID查看用户记录时,不会显示数据库的输出。 i have done this before but i didn't have any clue why this time it doesn't work. 我以前做过这个,但是我不知道为什么这次不起作用。
user_list.php user_list.php
<?php
include 'connection.php';
$sql = "SELECT * FROM formequip, equipment, department WHERE formequip.equip_id = equipment.equip_id = department.depart_id";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
?>
<div class="container" style="margin-top: 10px">
<table width="100%" border="0" class=" table table-striped table-bordered" id="mak_pekerja">
<thead>
<tr bgcolor="#666666">
<th width="2%" nowrap="nowrap">Bil</th>
<th width="2%" nowrap="nowrap">Jabatan</th>
<th width="14%" nowrap="nowrap">Nama</th>
<th width="7%" nowrap="nowrap">Kad Matrik</th>
<th width="9%" nowrap="nowrap">No.Telefon</th>
<th width="10%" nowrap="nowrap">Tarikh Pinjam</th>
<th width="12%" nowrap="nowrap">Tarikh Hantar</th>
<th width="15%" nowrap="nowrap">Aktiviti</th>
<th width="15%" nowrap="nowrap">Perkara</th>
<th width="15%" nowrap="nowrap">Kuantiti</th>
<th width="15%" nowrap="nowrap">Status</th>
<th width="16%" nowrap="nowrap">Tetapan</th>
</tr>
</thead>
<tbody>
<?php
$tmpCount = 1;
while ($row_lprn = mysql_fetch_assoc($result)) {?>
<tr bgcolor="#DDD">
<td><?php echo $tmpCount; ?></td>
<td><?php echo $row_lprn['department']; ?></td>
<td><?php echo $row_lprn['stud_name']; ?></td>
<td><?php echo $row_lprn['stud_id']; ?></td>
<td><?php echo $row_lprn['stud_tel']; ?></td>
<td><?php echo $row_lprn['stud_date_borrow']; ?></td>
<td><?php echo $row_lprn['stud_date_return'];?></td>
<td><?php echo $row_lprn['stud_activity']; ?></td>
<td><?php echo $row_lprn['equip_type']; ?></td>
<td><?php echo $row_lprn['stud_quantity']; ?></td>
<td><?php echo $row_lprn['stud_status']; ?></td>
<td><a href="update.php?id=<?php echo $row_lprn['id']; ?>" class="btn btn-mini btn-danger"> <i class="icon-list-alt icon-white"></i>Edit</a></td>
<td><input type="hidden" name="id" value="<?php echo $row_lprn['id']; ?>" /></td>
</tr>
<?php $tmpCount ++; }?>
</tbody>
</table>
update.php update.php
<?php
include('connection.php');
$sql = "SELECT * FROM formequip WHERE id='".$_POST['id']."'";
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
$id = $row_lprn['id'];
$stud_id = $row_lprn['stud_id'];
$equip_id = $row_lprn['equip_type'];
$stud_name = $row_lprn['stud_name'];
$stud_tel = $row_lprn['stud_tel'];
$stud_activity = $row_lprn['stud_activity'];
$stud_date_borrow = $row_lprn['stud_date_borrow'];
$stud_date_return = $row_lprn['stud_date_return'];
$equip_type = $row_lprn['equip_type'];
$stud_quantity = $row_lprn['stud_quantity'];
$id = $_POST['id'];
$submit = $_POST['submit'];
?>
<p>
<div id="form">
<form name="update" action="update2.php" method="post">
<table width="800" align="center">
<tr>
<td>No. ID</td>
<td>:</td>
<td><?php echo "$id"; ?></td>
</tr>
<tr>
<td>No. Matrik</td>
<td>:</td>
<td><?php echo "$stud_id"; ?></td>
</tr>
<tr>
<td width="173">Jabatan</td>
<td width="10">:</td>
<td width="564"><?php echo "$department"; ?></td>
</tr>
<tr>
<td>Nama Pemohon</td>
<td>:</td>
<td><?php echo "$stud_name"; ?></td>
</tr>
<tr>
<td>No. Telefon</td>
<td>:</td>
<td><?php echo "$stud_tel"; ?></td>
</tr>
<tr>
<td>Aktiviti</td>
<td>:</td>
<td><?php echo "$stud_activity"; ?></td>
</tr>
<tr>
<td>Tarikh Pinjam</td>
<td>:</td>
<td><?php echo "$stud_date_borrow"; ?></td>
</tr>
<tr>
<td>Tarikh Pulang</td>
<td>:</td>
<td><?php echo "$stud_date_return"; ?></td>
</tr>
<tr>
<td>Perkara</td>
<td>:</td>
<td><?php echo "$equip_type"; ?></td>
</tr>
<tr>
<td>Kuantiti</td>
<td>:</td>
<td><?php echo "$stud_quantity"; ?></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><label>
<select name="stud_status" id="stud_status">
<option selected="selected"></option>
<option>Diluluskan</option>
<option>Tidak Diluluskan</option>
</select>
</label>
</td>
</tr>
<p align="center">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="hidden" name="stud_name" value="<?php echo $stud_name; ?>">
</p>
</table><input name="submit" type="submit" id="submit" value="Kemaskini" />
</form><form action="user_list.php">
<input type="submit" value="kembali"></form>
</div>
</div>
</div>
the output will be displayed like this: 输出将显示如下:
thank you for your help :) 谢谢您的帮助 :)
You realy wanna make this query? 您真的要查询吗?
$sql = "SELECT * FROM formequip, equipment, department WHERE formequip.equip_id = equipment.equip_id = department.depart_id";
You are comparing equip_id from two tables, with depart_id from a third table. 您正在比较两个表中的equip_id和第三个表中的depart_id。
Next, you called "formequip.equip_id" at the first file, and formequip.id at the second. 接下来,你所谓的“formequip.equip_id”的第一个文件,并在第二formequip.id。
I think your problem should be solved by using this line: Edit: Use $_GET instead of $_POST 我认为您的问题应该通过使用以下行来解决:编辑:使用$ _GET代替$ _POST
$sql = "SELECT * FROM formequip WHERE equip_id=".$_GET['id'];
How did you declare Id in the database? 您如何在数据库中声明ID? if it is an integer, you have to remove the apostrophes from the query: 如果是整数,则必须从查询中删除撇号:
$sql = "SELECT * FROM formequip WHERE id=".$_POST['id'];
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.