我無法找出問題所在。我的McReport.php將顯示我之前從數據庫中輸入的所有數據。我只想顯示使用來自makemc.php的Id的McReport.php中的數據。請幫我找出解決問題的方法。謝謝。PHP從數據庫獲取數據請按照編號
//makemc.php database
if(isset($_POST['btnSubmit'])){
$AddMCQ = "INSERT INTO tblmc(Id,Name,FromDate,ToDate,Reason) VALUES('".$_POST['txtNo']."','".strtoupper($_POST['txtName'])."','".$_POST['txtFrom']."','".$_POST['txtTo']."','".strtoupper($_POST['txtReason'])."')";
$AddMCResult = mysql_query($AddMCQ,$link);
if($AddMCResult)
{
echo "<script language=\"JavaScript\">\n";
echo "alert('Record Added.');\n";
echo "window.location='McReport.php'";
echo "</script>";
}
//McReport.php
<?php
include("database.php");
$data = mysql_query("SELECT * FROM tblmc")
or die(mysql_error());
echo "<p align='center'><b>Dr. Ting EE Medical Clinic</b></p>";
echo "<p align='center'><font size='2'>MEDICAL CERTIFICATE</font></p>";
while($row= mysql_fetch_array($data))
{
$old_from_date = $row['FromDate'];
$old_from_date_timestamp = strtotime($old_from_date);
$new_from_date = date('d/m/Y', $old_from_date_timestamp);
$old_to_date = $row['ToDate'];
$old_to_date_timestamp = strtotime($old_to_date);
$new_to_date = date('d/m/Y', $old_to_date_timestamp);
echo "<p align='center'>THIS IS TO CERTIFY THAT <u>".$row['Name']."</u> IS RECEIVING MEDICAL</p>";
echo "<p align='center'>TREATMENT AND FOR THE PERIOD <u>".$new_from_date."</u> TO <u>".$new_to_date."</u> INCLUSIVE</p>";
echo "<p align='center'>HE WILL BE UNFIT TO CONTINUE HIS USUAL OCCUPATION</p>";
}
?>
因此在makemc.php必須把$ ID = $ _ POST [「txtNo」]; ?? – phpnewbie123 2014-10-26 15:44:13
是的,但是你需要將這個$ id傳遞給McReport.php。 最簡單的方法可能是SESSION。 確保你已經在** makemc.php **中初始化了它,並且使用 'if(session_id()=='){ session_start(); }' 分配$ _SESSION [ '身份證'] '$ _SESSION [ '身份證'] = $ _ POST [ 'txtNo']' 而在** ** McReport.php使用該查詢 '$ id = $ _SESSION ['id']; $ data = mysql_query(「SELECT * FROM tblmc WHERE Id ='$ id'」)或die(mysql_error()); ' – Dangeroustry 2014-10-26 15:53:12