Help ! How do I format output results to table ?

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

  1. #1
    Hi,

    I have some code whicj out puts the data as it should. However I want it to be formatted into a table like this -


    <table style="text-align: left; width: 600px;" border="1"
     cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </tbody>
    </table>
    
    HTML:



    At the moment its just outputs 1 col going down.

    here is the php code -


    <?
    
    $sql="select * from members,photos where members.username=photos.username and active=1 and approved='Y' ORDER BY UPLDATE DESC LIMIT 0, 5";
    $result = mysql_query($sql);
    
    
    						  $res=mysql_query($sql);
    						  while($obj=mysql_fetch_object($res))
    						  {
    					  		if($obj->url=="")
    							{
    								$img="<a href='http://www.pictures2rate.com/index.php?&username=$obj->username&phid=$obj->photosid''><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;
    
    ?>
    
    <table>
    <tr>
    <td><? print $img; ?><br /><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<? print $username; ?>">View <? print $username; ?>'s profile</a></td>
    </tr>
    </table>
    
    
    
    
    
                              <?
    						  }
    						  if($count!=0)
    						  {
    						  ?>
    
    
    
    
    
    
    
    						  <?
    						  }
    						  ?>
    PHP:
     
    Funk-woo10, Nov 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Nov 5, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    And try this
    
    <?
    
    $sql="select * from members,photos where members.username=photos.username and active=1 and approved='Y' ORDER BY UPLDATE DESC LIMIT 0, 5";
    $res=mysql_query($sql) OR die(mysql_error());
    $rows = 0;
    ?>
    <table>
    <tr>
    <?php
    
    while($obj=mysql_fetch_object($res))
    {
    
    	echo "<td>\n";
    
    	if($obj->url=="")
    	{
    		$img="<a href='http://www.pictures2rate.com/index.php?&username=$obj->username&phid=$obj->photosid''><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; 
    	?>
        	<br /><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<? print $username; ?>">View <? print $username; ?>'s profile</a>
        <?php
    
    	echo "</td>";
    	
    	if (++$rows % 2 == 0)
    	{
    		echo "</tr>\n<tr>\n";
    	}
    }
    
    ?> 
    
    </tr>
    </table>
    
    PHP:
     
    nico_swd, Nov 5, 2007 IP
    Funk-woo10 likes this.
  4. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry ! And thanks I will leave rep
     
    Funk-woo10, Nov 5, 2007 IP