Query column counter

Hi, I’ve been using asp for a while and now learning php, and have become stuck.

I want to display the results from my query over 4 columns in a loop, I have found a lot of information on it, but don’t have enough understanding of php to get it. So can someone explain it to me in layman’s terms?

What I have so far (which I suspect is quite wrong) >>

   <?php include('db_login.php');
    
    //Connect to database - Begin
    $connection = mysql_connect( $db_host, $db_username, $db_password );
    if (!$connection)    {
       die ("Could not connect to the database: <br />". mysql_error());
    }
    $db_select=mysql_select_db($db_database);
    if (!$db_select)
    {
       die ("Could not select the database: <br />". mysql_error());
    }    
     $query = "Select Merch_Desc Merchandise";
		$result = mysql_query( $query );
		if (!$result)
	    {
		    die ("Could not query the database : &nbsp;". mysql_error());
		}
	While ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
		$Desc= $row["Merch_Desc"];

	 }

$Counter=0
?>
<HTML>
<BODY>
<table>
 <tr>
   <td>Column 1</td><td>Column 2</td><td>Column 3</td><td>Column 4</td>
 <tr>
	<td><?=$Desc?></td>
<? if ($Counter=5)
	{
		$Counter=0"</tr>";
	} 
	
?>

</table>

Any help would be great(And if you happen see anything else in the code that can be improved on i would appreciate that too.)

MOD EDIT: Added code tags

I only see a minor syntax issue in your PHP code ( $Counter=0""; would throw a Warning I believe), so that’s not going to be too much of a problem (considering your ASP knowledge it shouldn’t be anything you couldn’t figure out on your own + a little bit of help from Google).

You need to take a serious look at your SQL query though. That’s where things go haywire. Also, it might be good to take a long sharp look at your while loop.

Sponsor our Newsletter | Privacy Policy | Terms of Service