Jump to content

populating a table


SLeeeperG

Recommended Posts

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,

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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?

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.