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
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++;
}

?>

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.