2017-04-09 16 views
0

我在PHP代碼加入兩個表寫了一個MySQL查詢不工作,但我不希望在結果sql查詢在我的網頁

我地點的詳細信息表中的所有列:

my place details table pic

我的登記表:

my registration table oic

我的代碼

  <?php 
$con= mysqli_connect("localhost", "root", "", "project"); 

     if(!$con) 
     { 
      die('not connected'); 
     } 
      $result= mysqli_query($con, "SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username 
      FROM placedetails inner join registration on placedetails.id=registration.id ;"); 



?> 
<div class="container"> 
<CENTER><h2>view Booking Details</h2> 
<table class="table table-bordered"> 

    <th>place</th> 
    <th>Travelling Date</th> 
    <th>Total Cost</th> 
    <th>Stay cost</th> 
    <th>Food cost</th> 
    <th>Travelling cost</th> 
    <th>User ID</th> 


     <?php 

      while($row =mysqli_fetch_array($result)) 

      { 
       ?> 
      <tr> 
       <td><?php echo $row['name']; ?></td> 
       <td><?php echo $row['doj']; ?></td> 
       <td><?php echo $row['total'] ;?></td> 
       <td><?php echo $row['stay'] ;?></td> 
       <td><?php echo $row['food'] ;?></td> 
       <td><?php echo $row['travel'] ;?></td> 
       <td><?php echo $row['username'] ;?></td> 

       <td><img src='".$row['choose']."'/></td>"; 
      </tr> 
     <?php 
      } 
      ?> 
      </table> 
      </div> 

我寫我的代碼,它的執行,但問題是數據不執行,有人可以幫助我與我的問題。

+1

嘗試運行在你的phpmyadmin這個查詢,看看你得到任何結果 – Akintunde007

+0

同樣喜歡網絡的showng onlt兩個表的id科拉姆內科拉姆名字和我和我的價值觀不一樣@Akin – gudisa

+0

如果ID的不匹配,那麼你不會得到任何結果 –

回答

0

中mysqladmin

在你的表地點的詳細信息創建一個新的入口調用ID_regist。 之後,更改或提供一個數字,對應於你在tabel登記號。

code php

對於連接創建一個connection.php。

<?php 
    $con= mysqli_connect("localhost", "root", "", "project"); 

     if(!$con) 
     { 
      die('not connected'); 
     } 
?> 

使你的數據庫更難以攻擊

主代碼

<?php 
include("connection.php"); 
?> 
<div class="container"> 

<CENTER><h2>view Booking Details</h2> 
<table class="table table-bordered"> 

<th>place</th> 
<th>Travelling Date</th> 
<th>Total Cost</th> 
<th>Stay cost</th> 
<th>Food cost</th> 
<th>Travelling cost</th> 
<th>User ID</th> 

<?php 
    $sql= 
    "SELECT ". 
    "pld.name, ". 
    "pld.doj, ". 
    "pld.total, ". 
    "pld.stay, ". 
    "pld.food, ". 
    "pld.travel, ". 
    "pld.username ". 
    "FROM placedetails pld ". 
    "inner join registration reg ". 
    "on pld.ID_regist=reg.id;"; 
    $result= mysqli_query($con, $sql); 
    if($result){ 
    while($row =mysqli_fetch_array($result)) 
     { 
?> 
      <tr> 
       <td><?php echo $row['name']; ?></td> 
       <td><?php echo $row['doj']; ?></td> 
       <td><?php echo $row['total'] ;?></td> 
       <td><?php echo $row['stay'] ;?></td> 
       <td><?php echo $row['food'] ;?></td> 
       <td><?php echo $row['travel'] ;?></td> 
       <td><?php echo $row['username'] ;?></td> 
       <td><img src='".$row['choose']."'/></td>"; // first there is no row, call chose 
      </tr> 
<?php 
     } 
    } 
    else{ 
     die("Error"); //Something of the type mysqli_error(connection); 
    } 
?> 
     </table> 
</div> 

關注該行的呼叫選擇,你不要在你的SQL查詢中使用。 如果這樣不能解決您的問題,請告訴我當我試圖幫助您時發生了什麼。

+0

tq u代碼,我做了一個旅遊和travls網站,用戶在網站上預訂可用的包,主要問題是我有2頁,一個是管理頁面和另一個是用戶頁面。如果用戶登錄到網站,他選擇任何旅遊包和書籍,然後在管理頁面有一個表,我想要的用戶名稱,他選擇的包,如果可能你可以提供該SQL查詢@Jose Marques – gudisa

+0

因此,如果我不足之處在於,你有一個客戶登記表tabel和一個tabel call placedetails。您希望在客戶選擇時存儲數據,以便管理員知道該客戶選擇了這些特定數據?如果這是你想要的,你必須更多地考慮你的數據庫,以及如何使用它來創建表之間的關係,以便你可以做你想做的事情。如果您不知道表格關係是什麼,請在google上進行搜索。如果您有任何困難,請問我會盡力提供幫助。 –

0

你必須改變位置表並添加registration_id。然後加入這個領域。

SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username 
FROM placedetails inner join registration on registration.id=place.registration_id