View only results in table with certain information (only when conformation = No)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manupr
    New Member
    • Jun 2010
    • 6

    #1

    View only results in table with certain information (only when conformation = No)

    I have two table here uncorfirmed booking and confirmed bookings

    I only want data to be listed in the unconfirmed booking table when conformation = no

    and in only want data to be lised in confirmed booking table when conformation = yes

    Any ideas of the code i would have to add and where to add it please

    thanks

    Code:
    <h1>Booking Table (Unconfirmed Booking)</h1>
    
    <?php
    
    include("config.php");
    
    $con = mysql_connect($mysql_host, $mysql_user, $mysql_password); 
     
    mysql_select_db($mysql_database, $con); 
    
    $result = mysql_query("SELECT * FROM names");
    
    echo "<table border='1'>
    <tr>
    <th>Booking ID</th>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Adress</th>
    <th>City / Town</th>
    <th>Postcode</th>
    <th>Phone Number</th>
    <th>E-Mail</th>
    <th>Cottage</th>
    <th>Start Date</th>
    <th>End Date</th>
    <th>Conformation</th>
    <th>Confirm Booking</th>
    <th>Delete Booking</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['bookid'] . "</td>";
      echo "<td>" . $row['firstname'] . "</td>";
      echo "<td>" . $row['lastname'] . "</td>";
      echo "<td>" . $row['address'] . "</td>";
      echo "<td>" . $row['citytown'] . "</td>";
      echo "<td>" . $row['postcode'] . "</td>";
      echo "<td>" . $row['phonenumber'] . "</td>";
      echo "<td>" . $row['emailaddress'] . "</td>";
      echo "<td>" . $row['cottage'] . "</td>";
      echo "<td>" . $row['startdate'] . "</td>";
      echo "<td>" . $row['enddate'] . "</td>";
      echo "<td>" . $row['conformation'] . "</td>";
      echo "<td><a href=\"conbook.php?bookid=". $row['bookid']."\" onclick=\"return confirm('Are you sure you want to confirm booking?');\"> Confirm </a></td>";
      echo "<td><a href=\"delbook.php?bookid=". $row['bookid']."\" onclick=\"return confirm('Are you sure you want to delete record?');\"> Delete </a></td>";
      echo "</tr>";
      }
    echo "</table>";
    
    mysql_close($con); 
    
    ?>
    
    <h1>Booking Table (Confirmed Booking)</h1>
    
    <p>
      <?php
    
    include("config.php");
    
    $con = mysql_connect($mysql_host, $mysql_user, $mysql_password); 
     
    mysql_select_db($mysql_database, $con); 
    
    $result = mysql_query("SELECT * FROM names");
    
    echo "<table border='1'>
    <tr>
    <th>Booking ID</th>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Adress</th>
    <th>City / Town</th>
    <th>Postcode</th>
    <th>Phone Number</th>
    <th>E-Mail</th>
    <th>Cottage</th>
    <th>Start Date</th>
    <th>End Date</th>
    <th>Conformation</th>
    <th>Unconfirm Booking</th>
    <th>Delete Booking</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['bookid'] . "</td>";
      echo "<td>" . $row['firstname'] . "</td>";
      echo "<td>" . $row['lastname'] . "</td>";
      echo "<td>" . $row['address'] . "</td>";
      echo "<td>" . $row['citytown'] . "</td>";
      echo "<td>" . $row['postcode'] . "</td>";
      echo "<td>" . $row['phonenumber'] . "</td>";
      echo "<td>" . $row['emailaddress'] . "</td>";
      echo "<td>" . $row['cottage'] . "</td>";
      echo "<td>" . $row['startdate'] . "</td>";
      echo "<td>" . $row['enddate'] . "</td>";
      echo "<td>" . $row['conformation'] . "</td>";
      echo "<td><a href=\"unconbook.php?bookid=". $row['bookid']."\" onclick=\"return confirm('Are you sure you want to unconfirm booking?');\"> Unconfirm </a></td>";
      echo "<td><a href=\"delbook.php?bookid=". $row['bookid']."\" onclick=\"return confirm('Are you sure you want to delete record?');\"> Delete </a></td>";
      echo "</tr>";
      }
    echo "</table>";
    
    mysql_close($con);
    	
    ?>
    <p>
      <INPUT type="button" value="Log Out" onClick="location.href='adminlog.php'">
      <html>
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Code:
    //Change line 11 to this
    $result = mysql_query("SELECT * FROM names WHERE conformation = 'yes'");
    
    //Change line 67 to
    $result = mysql_query("SELECT * FROM names WHERE conformation = 'no'");
    What you are doing is adding a where clause to pull the appropriate data based off your conformation field. Now I am assuming here that the field conformation is a string equal to yes or no and not a boolean.

    Comment

    Working...