www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP - Display SQL results in multiple tables

  1. #1
    Join Date
    Nov 2005
    Posts
    38

    PHP - Display SQL results in multiple tables

    I have a db table with student room assignments. Each student has a specific hall, floor, and apartment. I need to display each student in a specific table so the results look like a floor layout. Below is an example.

    Scan 14.jpg

    Here is what I started with, but all the results are just listed down the page. Any help would be great.

    Code:
    $query = "SELECT res.ID, res.APARTMENT
    FROM Residents res
    WHERE res.ROOM_ASSIGN_STS = 'A'
    and res.BLDG_CDE = '$pulledhall'
    and res.FLOOR = '$pulledfloor'";
    
    $result = odbc_exec($connect, $query); 
      
      while(odbc_fetch_row($result)){ 
      $ID = odbc_result($result,ID);
      $APARTMENT = odbc_result($result,APARTMENT);
    
      if ($APARTMENT == $pulledfloor.'01')
      {
      echo "<table>";
      echo $pulledfloor.'01';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
      else if ($APARTMENT == $pulledfloor.'02')
      {
      echo "<table>";
      echo $pulledfloor.'02';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
    
      else if ($APARTMENT == $pulledfloor.'03')
      {
      echo "<table>";
      echo $pulledfloor.'03';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
      else if ($APARTMENT == $pulledfloor.'04')
      {
      echo "<table>";
      echo $pulledfloor.'04';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
      else if ($APARTMENT == $pulledfloor.'05')
      {
      echo "<table>";
      echo $pulledfloor.'05';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
      else if ($APARTMENT == $pulledfloor.'06')
      {
      echo "<table>";
      echo $pulledfloor.'06';
      echo "<tr><td>";
      print $ID;
      echo "</td></tr>";
      echo "</table>";
      }
      }

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    640
    If I understand you, you should order your query by floor, then as you go thru the results check when the floor # changes, ending it the current html table and beginning a new one for each floor.

    Am I close?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles