Jump to content

[SOLVED] A good way to "loop" this output?


datafan

Recommended Posts

Here is the website, www.goodstylist.com

I am refering to the three pictures of "Todays Top Rated Stylists".

what I am trying to do is figure out a clean way to start a new table row for each 3 Stylists. So if I change my query to pull 12 instead of just 3, the output on the screen will just loop creating rows of 3 like the one there.

 

Here is what is driving it now:

 

$query = sprintf("SELECT username, thpicname1, realname, city, state, currentrate FROM users WHERE(thpicname1 !='') ORDER BY currentrate DESC LIMIT 0,3");

// Perform Query
GetMyConnection() or die(mysql_error());
$result = mysql_query($query);


if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}


echo "<table cellpadding='4' width='760'>";
echo "<tr>";
while ($row = mysql_fetch_assoc($result)) {
    $thumb = "files/userimages/" .$row['thpicname1'];

echo "<td border='3' width='250'><a href='files/profileview.php?find=".$row['username']."' target='_self'><img src='".$thumb."'></a><br>" .$row['realname']. "<br>"  . $row['city'] . " , " . $row['state'] . "<br>Current Rating " . $row['currentrate'] . "</td>";
}

mysql_free_result($result);
?>
</tr>
</table><br>

 

Thanks for any help, and how do you get your code to show up with all the colors here like it does in notepad++ ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/68059-solved-a-good-way-to-loop-this-output/
Share on other sites

Change your while loop to this:

 

<?php

$i = 0;
while ($row = mysql_fetch_assoc($result)) {
   $thumb = "files/userimages/" .$row['thpicname1'];

   if ($i == 3){ echo '<tr>'; $i=0;}

   echo "<td border='3' width='250'><a href='files/profileview.php?find=".$row['username']."' target='_self'>
   <img src='".$thumb."'></a><br>" .$row['realname']. "<br>"  . $row['city'] . " , " . $row['state'] . "
   <br>Current Rating " . $row['currentrate'] . "</td>";
   
$i++;
}

?>

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.