insert results in rows

Discussion in 'PHP' started by shotazi, Oct 28, 2007.

  1. #1
    I select results from database with limit 15 then i want to isernt them in three rows


    but i can't i am making this code:
    <table width="1%" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <?php
    $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15");
    while($row = mysql_fetch_array($gamedt)){
    $gameid = $row['gameid'];
    $title = $row['title'];
    $gameurl = $row['gameurl'];
    $gamepic = $row['gamepic'];
    $width = $row['width'];
    $height = $row['height'];
    $count = $row['count'];
    $category = $row['category'];
    ?>
    
        <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td>
    	
     
        
        <? }  ?>
      </tr>
     </table>
    PHP:
    in this example results are in one row and i want to insert them in three rows, in table like this
    <table>
    <tr>
    <td>5 results</td>
    </tr>
    <tr>
    <td>5 results</td>
    </tr>
    <tr>
    <td>5 results</td>
    </tr>
    </table>
    HTML:
    please help me :(
     
    shotazi, Oct 28, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <table width="1%" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <?php
    $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15");
    while($row = mysql_fetch_array($gamedt)){
    $gameid = $row['gameid'];
    $title = $row['title'];
    $gameurl = $row['gameurl'];
    $gamepic = $row['gamepic'];
    $width = $row['width'];
    $height = $row['height'];
    $count = $row['count'];
    $category = $row['category'];
    ?>
    
        <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td>
        
     
        
        <? }  ?>
      </tr>
     </table>
    PHP:
    you can try an x=0; above your while loop, and in your while loop
    x++;
    if ((x%5)==0) { 
    echo //code to make a new row
    }
    PHP:
     
    Lordy, Oct 28, 2007 IP
  3. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it does not work :(

    what i can to do? :(
     
    shotazi, Oct 29, 2007 IP
  4. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it seems like your code to display the table is outside of php
     
    Lordy, Oct 29, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Try this.
    
    <table width="1%" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <?php
    $gamedt = mysql_query("SELECT * FROM `n-games` ORDER BY `count` LIMIT 15");
    $rowcount = 0;
    
    while($row = mysql_fetch_array($gamedt))
    {
    	$gameid = $row['gameid'];
    	$title = $row['title'];
    	$gameurl = $row['gameurl'];
    	$gamepic = $row['gamepic'];
    	$width = $row['width'];
    	$height = $row['height'];
    	$count = $row['count'];
    	$category = $row['category'];
    	?>
    
        <td><center><? echo $title; ?></center> <a href="?page=play&file=<? echo $gameid; ?>"><img src="<? echo $gamepic; ?>" width="100" height="100" ></a></td>
        
       <?
       
    	if (++$rowcount % 3 == 0)
    	{
    		echo '</tr><tr>';
    	}
       
    }
    
    ?>
      </tr>
     </table>
    
    PHP:
     
    nico_swd, Oct 29, 2007 IP
  6. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    nico_swd
    yaaa it is workiing thannk you veerry much.
     
    shotazi, Oct 29, 2007 IP