onthespot Posted August 17, 2009 Share Posted August 17, 2009 Hey, I have a function that displays awards in the form of images. However, after every 10 images, i want it to start a new line or <tr>. Here is the code. <table><tr> <td colspan="10"><b><u>Awards:</u></b></td> <tr> <?php function awards($type) { $images = array ( 'league1' => 'first.jpg', 'league2' => 'second.jpg', 'league3' => 'third.jpg' ); if(array_key_exists($type, $images)) return '<td><img src="images/awards/'.$images[$type].'" width="8" height="18" /></td>'; return false; } $awarduser = mysql_real_escape_string($req_user_info['username']); $res=mysql_query("SELECT * FROM ".TBL_AWARDS." WHERE awarduser = '$awarduser' ORDER BY awarddate"); while($row=mysql_fetch_assoc($res)){ $type=$row['awardtype']; echo awards($type); } ?> </tr> </table> How would I go about getting the images to display 10 per row (td)?? Quote Link to comment Share on other sites More sharing options...
trq Posted August 17, 2009 Share Posted August 17, 2009 Read this FAQ. Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 I have just taken a look thankyou. I'm unsure how to adapt this into my code though? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 Ok i have the following <table><tr> <td colspan="10"><b><u>Awards:</u></b></td> <tr> <?php function awards($type) { $images = array ( 'league1' => 'first.jpg', 'league2' => 'second.jpg', 'league3' => 'third.jpg' ); if(array_key_exists($type, $images)) return '<td><img src="images/awards/'.$images[$type].'" width="8" height="18" /></td>'; return false; } $awarduser = mysql_real_escape_string($req_user_info['username']); $res=mysql_query("SELECT awardtype FROM ".TBL_AWARDS." WHERE awarduser = '$awarduser' ORDER BY awarddate"); while($row=mysql_fetch_assoc($res)){ $type=$row['awardtype']; echo awards($type); } if($res && mysql_num_rows($res) > 0) { $i = 0; $max_columns = 10; while($row = mysql_fetch_array($res)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($awardtype != "" && $awardtype != null) echo "<td>$awardtype</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> This doesnt seem to change anything though? Any ideas? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 How can i combine the following? I really have no idea where to even begin here? <table><tr> <td colspan="10"><b><u>Awards:</u></b></td> <tr> <?php function awards($type) { $images = array ( 'league1' => 'first.jpg', 'league2' => 'second.jpg', 'league3' => 'third.jpg' ); if(array_key_exists($type, $images)) return '<td><img src="images/awards/'.$images[$type].'" width="8" height="18" /></td>'; return false; } $awarduser = mysql_real_escape_string($req_user_info['username']); $res=mysql_query("SELECT awardtype FROM ".TBL_AWARDS." WHERE awarduser = '$awarduser' ORDER BY awarddate"); while($row=mysql_fetch_assoc($res)){ $type=$row['awardtype']; echo awards($type); } ?> </tr> </table> and <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT awardtype FROM ".TBL_AWARDS." WHERE awarduser = '$awarduser' ORDER BY awarddate"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 10; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($awardtype != "" && $awardtype != null) echo "<td>$awardtype</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> Thankyou Quote Link to comment 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.