show data of multiple tables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • obtrs
    New Member
    • May 2009
    • 27

    show data of multiple tables?

    show data of multiple tables?
    i have 3 tables i want to show the data from them to a page.

    table1 "trip"
    table2 "seat"
    table3 "user_informati on"

    show all the data of table one which is working its showing but how can i show multiple table data any ways.

    show all data of trip and seat

    from user_informatio n it shows

    first_name
    last_name

    all the tables have id with the same name.

    Table (trip) show all from this
    * id
    * from
    * to
    * date
    * fare

    Table (seat) show all from this also
    * id
    * seat

    Table (user_informati on) show only first_name and last_name
    * first_name
    * last_name
    * email
    * address
    * city
    * province
    * contact_no



    also show the last line which is entered in the id



    here is the code im using.

    Code:
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("online_bus_project", $con);
    
    $result = mysql_query("SELECT * FROM trip, seat, user_information ORDER BY `id` DESC LIMIT 1");  
    
    
    echo "<table border='1'>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>From</th>
    <th>To</th>
    <th>Date</th>
    <th>Fare</th>
    <th>Seat</th>
    
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['first_name'] . "</td>";
      echo "<td>" . $row['last_name'] . "</td>";
      echo "<td>" . $row['from'] . "</td>";
      echo "<td>" . $row['to'] . "</td>";
      echo "<td>" . $row['date'] . "</td>";
      echo "<td>" . $row['fare'] . "</td>";
      echo "<td>" . $row['seat'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";
    
    mysql_close($con);
    ?>
  • obtrs
    New Member
    • May 2009
    • 27

    #2
    any one????........ .......

    Comment

    • prabirchoudhury
      New Member
      • May 2009
      • 162

      #3
      show data of multiple tables?

      Code:
      <?php 
      $con = mysql_connect("localhost","root","password"); 
      if (!$con) 
        { 
        die('Could not connect: ' . mysql_error()); 
        } 
        
        mysql_select_db("online_bus_project", $con); 
        
        $result_trip = mysql_query("SELECT * FROM trip where booking_id=$booking_id"); 
        
        $result_seat = mysql_query("SELECT * FROM trip where booking_id=$booking_id"); 
        
        $result_user = mysql_query("SELECT * FROM user_information where user_information_id = $id and booking_id=$booking_id"); 
        
        $csr_trip = mysql_query($result_trip);
        $csr_seat = mysql_query($result_seat);
        $csr_user = mysql_query($result_user);
        // get the if is in database
      	$num_trip = mysql_num_rows($csr_trip);
      	$num_seat = mysql_num_rows($csr_seat);
      	$num_user = mysql_num_rows($csr_user);
      		 
      		  
      		  if ($num_trip > 0){ 
      		   while ($row=mysql_fetch_array($csr_trip)) {
        //trip table
      echo "<table border='1'> 
      <tr> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>From</th> 
      <th>To</th> 
      <th>Date</th> 
      <th>Fare</th> 
      <th>Seat</th> 
        
      </tr>"; 
        
      while($row = mysql_fetch_array($result)) 
        { 
        echo "<tr>"; 
        echo "<td>" . $row['first_name'] . "</td>"; 
        echo "<td>" . $row['last_name'] . "</td>"; 
        echo "<td>" . $row['from'] . "</td>"; 
        echo "<td>" . $row['to'] . "</td>"; 
        echo "<td>" . $row['date'] . "</td>"; 
        echo "<td>" . $row['fare'] . "</td>"; 
        echo "<td>" . $row['seat'] . "</td>"; 
        echo "</tr>"; 
        } 
      echo "</table>"; 
      }
      
      // seat table
       if ($num_seat > 0){ 
      		   while ($row=mysql_fetch_array($csr_seat)) {
        //
      echo "<table border='1'> 
      <tr> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>From</th> 
      <th>To</th> 
      <th>Date</th> 
      <th>Fare</th> 
      <th>Seat</th> 
        
      </tr>"; 
        
      while($row = mysql_fetch_array($result)) 
        { 
        echo "<tr>"; 
        echo "<td>" . $row['first_name'] . "</td>"; 
        echo "<td>" . $row['last_name'] . "</td>"; 
        echo "<td>" . $row['from'] . "</td>"; 
        echo "<td>" . $row['to'] . "</td>"; 
        echo "<td>" . $row['date'] . "</td>"; 
        echo "<td>" . $row['fare'] . "</td>"; 
        echo "<td>" . $row['seat'] . "</td>"; 
        echo "</tr>"; 
        } 
      echo "</table>"; 
      }
      // user table
      
       if ($num_user > 0){ 
      		   while ($row=mysql_fetch_array($csr_user)) {
        //
      echo "<table border='1'> 
      <tr> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>From</th> 
      <th>To</th> 
      <th>Date</th> 
      <th>Fare</th> 
      <th>Seat</th> 
        
      </tr>"; 
        
      while($row = mysql_fetch_array($result)) 
        { 
        echo "<tr>"; 
        echo "<td>" . $row['first_name'] . "</td>"; 
        echo "<td>" . $row['last_name'] . "</td>"; 
        echo "<td>" . $row['from'] . "</td>"; 
        echo "<td>" . $row['to'] . "</td>"; 
        echo "<td>" . $row['date'] . "</td>"; 
        echo "<td>" . $row['fare'] . "</td>"; 
        echo "<td>" . $row['seat'] . "</td>"; 
        echo "</tr>"; 
        } 
      echo "</table>"; 
      }
      mysql_close($con); 
      ?>

      Comment

      • obtrs
        New Member
        • May 2009
        • 27

        #4
        prabir i want this to be look like a ticket? what should i do?




        Code:
         <?php
        $con = mysql_connect("localhost","root","autodeskmaya");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
        
        mysql_select_db("online_bus_project", $con);
        
        
        
        echo "<table border='1' cellpadding='5' cellspacing='3' align='center' bgcolor='#ececec'>
        <tr>
        
        <th>Online Bus Ticket Reservation System - Traveling Ticket</th> 
        
        </tr>";
        
        echo "</table>";
        
        
        
        $result3 = mysql_query("SELECT ticket FROM ticket_number ORDER BY RAND() LIMIT 1");
        
        
        echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
        <tr>
        
        <th>Ticket Number</th> 
        
        </tr>";
        
        while($row3 = mysql_fetch_array($result3))
          {
          echo "<tr>";
          echo "<td>" . $row3['ticket'] . "</td>";
          echo "</tr>";
          }
        echo "</table>";
        
        
        
        
        
        
        
        //SELECT * FROM table ORDER BY RAND() LIMIT 1
        
        
        
        
        $result2 = mysql_query("SELECT first_name, last_name FROM user_information ORDER BY `id` DESC LIMIT 1");  
        
        
        echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
        <tr>
        
        <th>Name</th> 
        <th>Last Name</th>
        
        
        
        
        </tr>";
        
        while($row2 = mysql_fetch_array($result2))
          {
          echo "<tr>";
          echo "<td>" . $row2['first_name'] . "</td>";
          echo "<td>" . $row2['last_name'] . "</td>";
          echo "</tr>";
          }
        echo "</table>";
        
        
        
        
        
        
        $result = mysql_query("SELECT * FROM trip ORDER BY `id` DESC LIMIT 1");  
        
        
        echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
        <tr>\n
        <th>From</th>
        <th>To</th>
        <th>Date</th>
        <th>Paid Amount</th>
        
        
        
        </tr>";
        
        while($row = mysql_fetch_array($result))
          {
          echo "<tr>";
          echo "<td>" . $row['gender'] . "</td>";
          echo "<td>" . $row['country'] . "</td>";
          echo "<td>" . $row['date'] . "</td>";
          echo "<td>" . $row['fare'] . "</td>";
          echo "</tr>";
          }
        echo "</table>";
        
        
        $result1 = mysql_query("SELECT * FROM seat ORDER BY `id` DESC LIMIT 1");  
        
        
        echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
        <tr>\n
        <th>Seat</th>
        
        </tr>";
        
        while($row1 = mysql_fetch_array($result1))
          {
          echo "<tr>";
          echo "<td>" . $row1['seat'] . "</td>";
          echo "</tr>";
          }
        echo "</table>";
        
        
        
        
        
        
        
        
        mysql_close($con);
        ?>

        Comment

        • obtrs
          New Member
          • May 2009
          • 27

          #5
          i have done this to achive result but tables are mess? i want this to show a ticket look like a ticket havent worked with php styling and tables?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by obtrs
            i want this to show a ticket look like a ticket havent worked with php styling and tables?
            there's nothing like php styling (the styling is done via HTML/CSS), despite when you refer to the source code writing style…

            best is you draw how the ticket should look like, construct the according HTML/CSS and make PHP print it this way.

            Comment

            • obtrs
              New Member
              • May 2009
              • 27

              #7
              thanx.... but im trying inside of php tag its done via html but what when we access database tables which are inside php tags
              <?php

              ?>

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                without knowing what the output shall look like, there's no much sense to play around in PHP.

                make an example page (using example values) and make it look like you want it to be (we worry about the PHP issues later). once that is displaying correctly, we can consider how to get PHP printing it this way.

                Comment

                • obtrs
                  New Member
                  • May 2009
                  • 27

                  #9
                  thanx for the help im looking forward to it thanx.

                  Comment

                  Working...