Multiple Collumns of results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
templatesforall
Forum Newbie
Posts: 5
Joined: Thu Jul 24, 2003 2:39 am
Location: Tucson, Arizona
Contact:

Multiple Collumns of results

Post by templatesforall »

I'm trying to make my results in 2 columns. Right now the results get outputted to the browser in a single column. Any Ideas?
I want to go from this:

1
2
3
4

To this:

1 2
3 4

I've read tutorials online and no dice. I'm still confused.

Code: Select all

<?
if (!$cat){
$cat = "business";
}

require("templatesettings.php");

$db_connect = mysql_connect($sqlhostname,$login,$password);
$base_selection = mysql_select_db($base,$db_connect);

$query = "SELECT * FROM templates WHERE category = '$cat'";
$req = mysql_query($query);

if (!$req)
{ echo "<B>Error ".mysql_errno()." :</B> ".mysql_error()."";
exit; }
$res = mysql_num_rows($req);

if ($res == 0)
   { echo "<center><b>Sorry there are no templates in this category yet.</b></center>";}
else 
   { while($row = mysql_fetch_array($req))
            {
               extract($row);
if ($rating == 0 || $votes == 0){
$showrate = 0;
} else {
 $showrate = round($rating/$votes, 1);
}
  print( "<table width="300" cellspacing="0" cellpadding="5">\n" );
  print( "  <tr>\n" );
  print( "      <td><img src="$thumb" width="100" height="80" border="0" alt="Screenshot of Template #$ID"></td>\n" );
  print( "      <td align="right">Author: $author<br />\n" );
  print( "Downloads: $download<br />\n" );
  print( "Rating: $showrate<br />\n" );
  print( "<form action="rate.php" method="post">\n" );
  print( "<select name="rating">\n" );
  print( "<option value="5">EXCELENT</option>\n" );
  print( "<option value="4">VERY GOOD</option>\n" );
  print( "<option value="3">GOOD</option>\n" );
  print( "<option value="2">FAIR</option>\n" );
  print( "<option value="1">POOR</option>\n" );
  print( "</select><input name="id" type="hidden" value="$ID">\n" );
  print( "&nbsp;<input type="submit" value="Vote!">\n" );
  print( "</form>" );
  print( "</td>\n" );
  print( "  </tr>\n" );
  print( "  <tr>\n" );
  print( "  <td colspan="2" align="center">\n" );
  print( "  <a href="$get" target="_BLANK">DOWNLOAD</a> | <a href="$view" target="_BLANK">VIEW</a>\n" );
  print( "  </td>\n" );
  print( "  </tr>\n" );
  print( "</table>\n" );
  print( "<hr size="1" noshade color="black"><br />\n" );
    }
mysql_free_result($req);
}

?>
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

try adding a counter to determine the ending of the table row and the beginning of the next. Something like this:

Code: Select all

$i=0;
while(list($val)=mysql_fetch_array)&#123;
   
   if($i < 1)&#123;
       print"<tr>\n";
   &#125;
   print"<td>$val</td>\n";
   if($i >1)&#123;
        print"</tr>\n";
        $i=0;
    &#125;
    else&#123;
        $i++;
    &#125;
&#125;
Post Reply