iChriss Posted January 20, 2011 Share Posted January 20, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/ Share on other sites More sharing options...
Muddy_Funster Posted January 20, 2011 Share Posted January 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/#findComment-1162384 Share on other sites More sharing options...
iChriss Posted January 20, 2011 Author Share Posted January 20, 2011 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: () () () () () () () Quote Link to comment https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/#findComment-1162457 Share on other sites More sharing options...
mikosiko Posted January 20, 2011 Share Posted January 20, 2011 answer is here http://www.phpfreaks.com/forums/faqcode-snippet-repository/ Quote Link to comment https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/#findComment-1162556 Share on other sites More sharing options...
iChriss Posted January 21, 2011 Author Share Posted January 21, 2011 Thanks! God you don't know how long I've been searching for a code like this Quote Link to comment https://forums.phpfreaks.com/topic/225061-mysql-php-results-per-line/#findComment-1162806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.