Jump to content


Photo

Table With Fetch


  • Please log in to reply
6 replies to this topic

#1 Cloud9247

Cloud9247
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationMy Computer

Posted 10 July 2006 - 07:12 PM

I have been developing my graphics site lately, and I have run into a problem. Currently I am setting up a 100x100 avatars page, and I am using mysql_fetch_array. I want it to have in each row of avatars, 4 avatars per row. and I am currently using tables for this, so can someone help me get it to where every 4 rows it inserts a '<tr>' and '</tr>', so I could get more rows?

#2 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 10 July 2006 - 07:15 PM

Have you tried testing this in you loop?

<?php
$i=0;
while ($row = $result->fetch_object()) {
    if ($i == 3) { // 4
         $content .= '<tr>';
         $i = 0;
    }
}

Zend Certified Engineer (ZEND001989)
www.willfitch.com

#3 Cloud9247

Cloud9247
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationMy Computer

Posted 10 July 2006 - 07:39 PM

no, I haven't. But I don't really know how to implement that either.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 July 2006 - 07:46 PM

<?php
$sql = "some query";
$result = mysql_query($sql);
$i = 0;
echo "<table><tr>";
while ($list = mysql_fetch_array($result)) {
   echo "<td>{$list['columnamehere']}</td>";
   if ($i == 3) {
      echo "</tr><tr>";
      $i = 0;
   } 
   $i++;
}
echo "</tr></table>"
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 Cloud9247

Cloud9247
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationMy Computer

Posted 10 July 2006 - 08:22 PM

<?php
echo $top1.'Avatars'.$top2.$body1;
echo '<table id= "avatars"><tr>';
$i= 0;
         $sqll= "SELECT userid, id, clicks, username, submitted, name, credits, comments, series, imgurl, active FROM avatars WHERE active='1' ORDER BY `id` DESC LIMIT $from, $max_results"; // LIMIT $from, $max_results
$rss= mysql_query( $sqll, $connection );
while($row= mysql_fetch_array( $rss )) {


$dwn= "return false;";


echo '<td id= "avi"><a href= "http://hayalkarga.com/designs.php?viewavatar='.$row['id'].'"><img src= "'.$row['imgurl'].'" id= "graphic" alt= "'.$row['name'].'" oncontextmenu="return false"></a></td>';

   if ($i == 3) {
      echo "</tr><tr>";
      $i = 0;
   } 
$i++;
}
echo '</tr></table>';
echo $body2.$foot1.$foot2;

comes out as: http://hayalkarga.co...designs=avatars

It prints out 4 on the first row, but only 3 on the others. Can someone help me fix this?

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 08:29 PM

That's because after setting $i=0 it then adds one before starting the loop.

Replace $i==3 with $i==4 and before the loop replace $i=0; with $i=1;
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 Cloud9247

Cloud9247
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationMy Computer

Posted 10 July 2006 - 08:33 PM

Actually, I just figured out to replace it with $i= -1, which works fine, thanks for your help everyone!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users