2017-02-10 14 views
1

私は、readmsg.phpと呼ばれるすべての顧客名を表示する要約ページを持っており、各顧客はMySQLデータベース内で固有のmsgidを持っています。もう片方のページはreadmsgdetail.phpという名前の詳細を表示できます。PHPでidを使用したURL herfリンクを表示MySQL

しかし、私はmsgidを使用して1つの顧客の詳細だけを表示する際に問題を抱えています。今のところ、私の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

私は

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

に私のselect文を変更した後それは 'データが見つかりません' を示していません。

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

readmsgdetail.phpのコードはに変更する必要があります:

+0

'WHERE'節を' SELECT'に追加します。 –

+0

"$ stmt = $ DB_con-> prepare(" firstname、lastname、phone、SELECT FROM user_message where msgid = 'msgdetail_id' ");"データが見つからないことを示します。 – xhinvis

+0

'msgid = 'msgdetail_id''これは' msgid'が 'int'で文字列を渡すためです。 –

答えて

0

はreadmsg.phpのコードはに変わります。これは、今ウォーキングれる

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

!コメントからの助けのためのThx!

関連する問題