Jump to content

MySQL + PHP - Results per line


iChriss

Recommended Posts

Hey everyone.

 

So I am coding a badge system for my website usersystem. I am trying to think how I'll handle issues before actually starting to code it and one issue I just can't seem to figure out how to handle..

 

How would I limit the amount of MySQL results to show per line.

Eg. A user has 6 badges but I'd only like to show 2 per line. So in total it'd show 3 lines with 2 badges per line. If that makes any sense?

 

Is there any way possible to actually do this?

Link to comment
https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/
Share on other sites

Output formating is not done with SQL.  It may help if you think of each language working like this:

SQL - Data Storage & Retrieval --> PHP - Data Manipulation --> HTML + CSS - Data Preasentation.

 

By telling your HTML to format the data in a two column table then you will get the results to apear as you described.

Yeah but is there any way to do it with this type of sql? If not do you have a suggestion of what SQL I should use?

 

$fetch1 = mysql_query("SELECT * FROM `badges` WHERE `uid` = '$logged[username]'");

echo "<table cellspacing='10' cellpadding='2' border='0'><tr>";

while ($badge = mysql_fetch_array($fetch1))
{
echo "<td valign='top'>";
echo "<a href='badge.php?id=$badge[id]'><img src='$badge[image]' border='0' width='50' height='50'></a>";
echo "</td>";
}

echo "</tr></table>";

 

That displays the badges fine, but obviously it just shows all the badges in one row, instead of two badge per line before it starts another.

 

So I want it like: () = Badge by the way

 

() ()

() ()

() ()

 

But it is showing like:

 

() () () () () () ()

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.