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
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>';
?>

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.