How do I format my results ?

Discussion in 'PHP' started by Funk-woo10, Nov 2, 2007.

  1. #1
    Hi all,

    When I ouput my query to the page I want it listed in a table like this-

    TABLE
    result1 result2
    result3 result4
    result5 result6

    The script displays 5 results only. Script -

    
    <?
    
    $sql="select * from members,photos where members.username=photos.username and active=1 and approved='Y' ORDER BY UPLDATE DESC LIMIT 2, 5";
    $result = mysql_query($sql);
    
    
    						  $res=mysql_query($sql);
    						  while($obj=mysql_fetch_object($res))
    						  {
    					  		if($obj->url=="")
    							{
    								$img="<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>";
    							}
    							else
    							{
    								$img="<a target='_blank' href='$obj->url'><img  border=0 width=100 height=100 src='$obj->url'></a>";
    							}
    
    						  $id=$obj->photosid;
    						  $username=$obj->username;
    
    ?>
    
    
    
    							<? print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<? print $username; ?>">View<? print $username; ?> profile</a>
    
    
    
    
    
    
                              <?
    						  }
    						  if($count!=0)
    						  {
    						  ?>
    
    
    
    
    
    
    
    						  <?
    						  }
    						  ?>
    
    
    PHP:
     
    Funk-woo10, Nov 2, 2007 IP
  2. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Any help people ?
     
    Funk-woo10, Nov 2, 2007 IP
  3. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #3
    The LIMIT 2, 5 in the sql statement will limit the amount that is returned you want 6 you should make it return 6 starting from mysql entry 2. 2, 6; :). I do not see any table formating in the output. Have you tried to do the table structure for it?
    
    <?php
    
      $sql = "select * from members,photos where members.username = photos.username and active = 1 and approved = 'Y' ORDER BY UPLDATE DESC [B]LIMIT 2, 6[/B]";
    
      $res = mysql_query($sql);
      while ($obj = mysql_fetch_object($res))
      {
    
          $id = $obj->photosid;
          $username = $obj->username;
    
          if ($obj->url == "") { $img = "<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>"; }
          else { $img = "<a target='_blank' href='$obj->url'><img  border=0 width=100 height=100 src='$obj->url'></a>"; }
    
    ?>
    <?php print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<?php print $username; ?>">View<?php print $username; ?> profile</a>
    <?php }
    if ($count != 0) { ?>
    
    
    PHP:
     
    exodus, Nov 2, 2007 IP
  4. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No Thats what I need help with - the table formatting
     
    Funk-woo10, Nov 2, 2007 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    
    <table border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    </table>
    Code (markup):
    That is a table like you want. So, basicly you need to use a counter to count up to two for each loop of the information and then output a </tr><tr> and then set the counter back to zero after you have done that. Put the table outside the while statement and put the </table> bottom of the while statement. At least that is what I end up doing. You could also use <div> floating left and right then clear. Output 1-X in the float left and when the counter hit that amount then output the x-6 in the right float and then just clear both floats and then do it that way.

    
    <?php
    
      $sql = "select * from members,photos where members.username = photos.username and active = 1 and approved = 'Y' ORDER BY UPLDATE DESC LIMIT 2, 6";
    
      $res = mysql_query($sql);
      echo "<table><tr>";
      while ($obj = mysql_fetch_object($res))
      {
    
          $id = $obj->photosid;
          $username = $obj->username;
    
          if ($obj->url == "") { $img = "<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>"; }
          else { $img = "<a target='_blank' href='$obj->url'><img  border=0 width=100 height=100 src='$obj->url'></a>"; }
    
    ?>
    <?php echo "<td>"; print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<?php print $username; ?>">View<?php print $username; ?> profile</a></td>
    <?php 
    $count++;
    if($count == 2) { echo "</tr><tr>"; $count = 0;}
    }
    echo "</tr></table>";
    if ($count != 0) { ?>
    
    PHP:
     
    exodus, Nov 2, 2007 IP
  6. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Could you show an example im not sure how to do this.
     
    Funk-woo10, Nov 2, 2007 IP