Jump to content

New line


onthespot

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/170628-new-line/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/170628-new-line/#findComment-899970
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/170628-new-line/#findComment-899984
Share on other sites

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.