我想知道从最近几周开始我是php的初学者。如何从mysql数据库中检索特定的数据行并显示到html表中。首页将s_no
作为URL parameter id
传递到第二页。所以第二页需要选择它(i.e. id = $_GET['id'])
,然后我在SQL查询中使用它来添加WHERE s_no = id
。但它不起作用。
下面是我的第二页编码。
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password ="";
$mysql_database = "iaoform_db";
// Create connection
$conn = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id']; //read id from get inputs
$sqli = "SELECT s_no, title_pro, type, cycle, type_pro, thesis, year,
proposer, institute,
email,present,contact,abstract,status_ongoing,status_file,
sch_request,no_night,no_night_impossible,just_request,instru1,mode_ob,
brief_descrip,plan,hfosc_b,hfosc_n,hfosc_g,hfosc_s,hesp_r,hesp_o,
tirspec_b,tirspec_n,tirspec_s,tirspec_c,tirspec_slits,obj_name,obj_ra,
obj_dec,obj_epoch,obj_mag,obj_size,scient_just,date
FROM forms WHERE s_no = ? "; //add a where clause with place holder
$stmt = $conn->prepare($sqli);
$stmt->bind_param('i', $id); //bind input parameters
$stmt->execute();
$stmt->store_result();
/* Get the number of rows */
$num_of_rows = $stmt->num_rows;
/* Bind the result to $row variable */
$stmt->bind_result($row);
if($num_of_rows < 1){ //exit or send the result if number of rows is less than one
echo "Can't find any record!";
mysqli_close($conn);
exit();}
?>
<!---------------------------------------------------->
<?php
while ($stmt->fetch()){
?>
<table class="tg" id="myModal">
<tr>
<th class="tg-9hbo">S.No</th>
<th class="tg-yw4l" colspan="5"><?php echo $row["s_no"]; ?> </th>
</tr>
<tr>
<td class="tg-9hbo">Title of the proposal:</td>
<td class="tg-yw4l" colspan="5"><?php echo $row["title_pro"]; ?>
</td>
</tr>
|
|
|
|
|
<tr>
<td class="tg-9hbo">Scientific Justification:</td>
<td class="tg-yw4l" colspan="5"><?php echo $row["scient_just"]; ?>
</td>
</tr>
<tr>
<td class="tg-9hbo">Submission date:</td>
<td class="tg-yw4l" colspan="5"><?php echo $row["date"]; ?> </td>
</tr>
</table>
<?php
$stmt->free_result();
}
mysqli_close($conn);
?>
非常感谢你。 :)