2017-02-10 18 views
1

我有一个摘要页面,它将显示所有名为readmsg.php的客户名称,每个客户在MySQL数据库中都有一个唯一的msgid。其他页面可以查看它们的详细信息,称为readmsgdetail.php。在PHP中使用id显示URL herf链接

但是,我在使用msgid显示一个客户的详细信息时遇到问题。现在,我的readmsgdetail.php可以显示所有客户的所有细节。

我readmsg.php代码:

 <div class="row"> 
     <?php 
     $stmt = $DB_con->prepare('SELECT firstname,lastname,phone,enquiry FROM user_message ORDER BY msgid DESC'); 
     $stmt->execute(); 

     if ($stmt->rowCount() > 0) { 
      while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
       extract($row); 
       ?> 
       <div class="col-xs-12"> 
        <p><a class="page-header" href="readmsgdetail.php?msgdetail_id=<?php echo $row['msgid']; ?>"><?php echo $lastname . $firstname; ?></a></p> 
       </div>  
       <?php 
      } 
     } else { 
      ?> 
      <div class="col-xs-12"> 
       <div class="alert alert-warning"> 
        <span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ... 
       </div> 
      </div> 
      <?php 
     } 
     ?> 
    </div> 

我readmsgdetail.php代码:

<?php 
require_once 'dbconfig.php'; 
//////------------------------------------------------ 
session_start(); 
if (empty($_SESSION) || empty($_SESSION['login_id'])) { 
    header('location:login.php'); 
}; 
echo"Welcome!! " . $_SESSION['login_id'] . " "; 
echo '<a href="logout.php">log out</a>'; 
//----------------------------------------------------- 

if (isset($_REQUEST['msgdetail_id']) && !empty($_REQUEST['msgdetail_id'])) { 
    $id = $_REQUEST['msgdetail_id']; 
} else { 

    header("Location: readmsg.php"); 
} 
?> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" /> 
     <title></title> 
     <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> 


     <link href="../bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/> 
    </head> 
    <body> 




     <div class="container"> 


      <div class="page-header"> 
       <h1 class="h2">User review <a class="btn btn-default" href="readmsg.php"> all reviews </a></h1> 
      </div> 



      <?php 
      $stmt = $DB_con->prepare('SELECT firstname,lastname,phone,enquiry FROM user_message ORDER BY msgid DESC'); 
      $stmt->execute(); 

      if ($stmt->rowCount() > 0) { 
       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
        extract($row); 
        ?> 
        <form method="post" enctype="multipart/form-data" class="form-horizontal"> 




         <table class="table table-bordered table-responsive"> 

          <tr> 
           <td><label class="control-label">Name.</label></td> 
           <td><input class="form-control" type="text" name="name" value="<?php echo $lastname . $firstname; ?>" required /></td> 
          </tr> 



          <tr> 
           <td><label class="control-label">Phone </label></td> 
           <td><input class="form-control" type="text" name="phone" value="<?php echo $phone; ?>" required /></td> 
          </tr> 

          <tr> 
           <td><label class="control-label">Feedback/Enquiry.</label></td> 

           <td><input class="form-control" type="text" name="comment" value="<?php echo $enquiry; ?>" required /></td> 

          </tr> 

          <tr> 
           <td colspan="2"> 
            <a class="btn btn-default" href="readmsg.php"> <span class="glyphicon glyphicon-backward"></span> back </a> 

           </td> 
          </tr> 
         </table> 
        </form>  
        <?php 
       } 
      } else { 
       ?> 
       <div class="col-xs-12"> 
        <div class="alert alert-warning"> 
         <span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ... 
        </div> 
       </div> 
       <?php 
      } 
      ?> 

     </div> 
    </body> 
</html> 

的MySQL stucture: enter image description here

目前的结果为网页:

enter image description here

后,我改变我的select语句

$stmt = $DB_con->prepare("SELECT firstname,lastname,phone,enquiry FROM user_message where msgid = 'msgdetail_id'"); 

它显示 '未发现数据'。

+0

将'WHERE'子句添加到'SELECT'。 –

+0

我更改为“$ stmt = $ DB_con-> prepare(”SELECT firstname,lastname,phone,inquiry FROM user_message where msgid ='msgdetail_id'“);”它没有显示数据。 – xhinvis

+0

'这里的msgid ='msgdetail_id''是因为msgid是int而你试图传递一个字符串。 –

回答

0

在readmsg.php的代码应该改为:

$stmt = $DB_con->prepare('SELECT msgid, firstname,lastname,phone,enquiry FROM user_message ORDER BY msgid DESC'); 

在readmsgdetail.php的代码应该改为:

$stmt = $DB_con->prepare("SELECT firstname,lastname,phone,enquiry FROM user_message where msgid=$id"); 

现在这是沃金! Thx从评论的帮助!

相关问题