SLeeeperG Posted January 7, 2008 Share Posted January 7, 2008 here's what I'm trying to do, fill a table with images, for each member ID, to be used on a welcome page for our gaming squad. here's what I have; $start = 0; $perpage = 4; $query1 = mysql_query("SELECT `user_id` , `medal_id` , `reason`, `time` FROM `user_medals` WHERE 1 AND `user_id` = $info[iD] ORDER BY `user_id` ASC limit $start, $perpage"); $result = mysql_query ($query1)or die ("Query failed"); $medal = mysql_fetch_array(mysql_query("select name, image from medals where ID = $row[medal_id]")); $i=-1; echo "<table>n<tr>n"; $num_cols=4;//desired number of columns while($output=mysql_fetch_object($result)){ $i++; if($i%$num_cols==0&&$i<>0){ echo"</tr>n<tr>n"; } echo "<td><img src=\"$medal[image]\" width=\"99\" height=\"26\" alt=\"$row[reason]\" /></td>n"; } echo "</tr>n</table>n"; I can't seem to get it to display 4 images, then start the next row. Any Help with this will be greatly appreciated, Quote Link to comment https://forums.phpfreaks.com/topic/84839-populating-a-table/ Share on other sites More sharing options...
Cazrin Posted January 7, 2008 Share Posted January 7, 2008 Hi there, I recently want this on my website and managed to get it to work. I was using DIVs instead of tables but give this a try: $counter = 0; while($output=mysql_fetch_object($result)){ echo "<td><img src=\"$medal[image]\" width=\"99\" height=\"26\" alt=\"$row[reason]\" /></td>n"; $counter++; if($counter == $num_cols) { echo "</tr> <tr>"; } That's the way round I did it, rather than before the line of code. Let me know if that works Quote Link to comment https://forums.phpfreaks.com/topic/84839-populating-a-table/#findComment-432552 Share on other sites More sharing options...
SLeeeperG Posted January 7, 2008 Author Share Posted January 7, 2008 Hi Cazrin, Thanks so much for getting back to me, I'll give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/84839-populating-a-table/#findComment-432848 Share on other sites More sharing options...
seawolf77 Posted January 7, 2008 Share Posted January 7, 2008 Hi Cazrin thanks for the replay.. the scripts you wroted not working or im just a noob.. this is the current scripts we have $start = 0; $perpage = 30; $query1 = mysql_query("SELECT `user_id` , `medal_id` , `reason`, `time` FROM `user_medals` WHERE 1 AND `user_id` = $info[iD] ORDER BY `user_id` ASC limit $start, $perpage"); $count = mysql_num_rows($query1); if($count >= 1) { echo "<table><div align=\"right\"><tr>"; while($row = mysql_fetch_array($query1)) { $medal = mysql_fetch_array(mysql_query("select name, image from medals where ID = $row[medal_id]")); $i=-1; $num_cols=4;//desired number of columns echo "<td><img src=\"$medal[image]\" width=\"99\" height=\"26\" alt=\"$row[reason]\" /></td>"; } } else { echo "<b>Sorry $_SESSION[username]! you dont have any medals yet!</b><br /><br />"; } echo "</div></table>"; } everythings work fine, the medals printed horizonatlly, but my problems untill now are, how do i printed like this |||||||| ||||||||| ||||||||||| ||||||||||| |||||||| ||||||||| ||||||||||| ||||||||||| right now it just printed from left to the right without breaking :-\ ||||||| |||||||||| ||||||||| ||||||||| |||||||||| |||||||||||| ||||||||||| |||||||||||||| |||||||||| |||||||||||||| |||||||||||||||| and im just at the point of gave up this work, perhaps someone can divided those info into 4 coloumn and make a new coloumn for it. $i=-1; $num_cols=4;//desired number of columns i guess something todo with this code, not finished perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/84839-populating-a-table/#findComment-433022 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.