Jump to content

Setting # of items per row from database...


jch02140

Recommended Posts

I am trying to do something like this

 

img.gif

 

but the code I have doesn't seem to do what I want...

 

<?php
   while($item_rows = mysql_fetch_array($item_result))
   { 
   	  $output = "        
              <tr bgcolor=\"#000000\">              
                <td align=\"center\"><p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p>
                  <p>".$item_rows['name']."<br />
                    Attack: +".$item_rows['attack']."<br />
                    <img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p>
                  <p>[Equipt|Destory]<br />
                  </p>
                </td>";
          $remainder = $i % 5;
	  
	  echo ($remainder == 0 ? ($i == 0 ? "" : "\n</tr>")."\n$output " : $output);
   }
       $colspan = (4 - $remainder);
   $last_row = $colspan ? "  <td ".($colspan? "colspan=$colspan" : "")."></td>" : "";
   echo $last_row. "
        </tr>
      </table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/247716-setting-of-items-per-row-from-database/
Share on other sites

Thats a good point :)

 

Just for fun.. you can do this without messing with tables and such.. Good old floated divs :)

 

<?php
echo '<div id="wrapper">';
$i = 0;
while($item_rows = mysql_fetch_array($item_result)){ 
echo "<div style=\"float:left;text-align:center\">
	<p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p>
	<p>".$item_rows['name']."<br />
	Attack: +".$item_rows['attack']."<br />
	<img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p>
	<p>[Equipt|Destory]<br />
	</p>
</div>";
}
echo '<div style="clear:both">
</div>';
?>

I just noticed a few errors of my code earlier.. I have updated the code and now able to display the correct number of records...

However, all records display are the last record in the database...

 

       <?php
   for ($i=0; $i<$count_result; $i++)
   { 
   	  $output = "                      
                <td align=\"center\"><p><img src=\"../images/".$item_rows['item_id'].".gif\" width=\"45\" height=\"45\" /></p>
                  <p>".$item_rows['name']."<br />
                    Attack: +".$item_rows['attack']."(".$item_rows['damage'].")<br />
                    <img src=\"../images/credit.gif\" width=\"17\" height=\"17\" />$".$item_rows['sell_price']."</p>
                  <p>[Equipt|Destory]<br />
                  </p>
                </td>";
          $remainder = $i % 5;
	  
	  echo ($remainder == 0 ? ($i == 0 ? "" : "\n</tr>")."\n$output " : $output);
   }
       $colspan = (4 - $remainder);
   $last_row = $colspan ? "  <td ".($colspan? "colspan=$colspan" : "")."></td>" : "";
   echo $last_row. "
        </tr>
      </table>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.