Avatar of Jon C
Jon C
 asked on

PHP Query result into two columns

Hi All

I am having a few issues trying to get the following to work, I am querying a DB and want the results to display into two equal columns, I can get all the results to display correctly in the first column, but i need half of them to display in the second column, the query displays a picture and a product title from the DB:


<div class="grid_6 alpha" id="left-column">				
	
		<div class="left-column">					
				<h1>Man<span style="color: #FF0">Products</span></h1>
				<p>Our Man Products..</p> <br />
<?php

	//session_start();
	include "admin/sql_comm_helper.php";
	include "admin/sql_data.php";  // File that contains the SQL connection information.
	login_mysql();
	select_db(FALSE);
	$fid = $_POST['fid'];
$data = mysql_query("SELECT * FROM upload WHERE manufacturer='Man'") 
or die(mysql_error()); 

Print "<table border cellpadding=3>";  
while($info = mysql_fetch_array( $data ))  
{  
print "<tr>";  
print '<td><p><img src="download.php?fid='.$info['fid'] . '" width="125" height="125"></td>'; 
print "<td><a href='product.php?fid=".$info['fid'] . "'><span style='font-size: 18px;'>".$info['productname'] ."</span></a></P></td> "; 
}  
print "</table>";
?> 



		</div>	<!--END SERVICES--> 
		
	</div>	<!--END LEFT COLUMN  id="left-column"-->

	
<!--========================================RIGHT COLUMN================================================-->
		<div class="grid_6" id="right-column">
		  <div class="left-column">
		    <h1>&nbsp;</h1>
		    <p>&nbsp;</p>
<br />
		    




	      </div>
		</div>
  <p>
		  <!--END RIGHT COLUMN-->

Open in new window



Many thanks

Jon
PHPHTMLWeb Languages and Standards

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon
Chris Stanyon

Do you mean two columns within the table, or spread across the two DIVs - left-column / right-column.
Jon C

ASKER
Hi, thanks for the reply, sorry if my explanation wasnt clear

I need it spread across two DIVs

I have included the second DIV in the code above, the code is in the first DIV which appears on the left of the page, but if there are a lot of results the page ends up being quite long, therefore I want half of the results to appear in the second DIV on the right of the page

Thanks
SOLUTION
Chris Stanyon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jon C

ASKER
Hi  

Thanks again for your reply, I am trying to use your first suggestion as i think that would fit best with what i am trying to achive, I have edited the code as below, but I am getting a 500 Internal Server Error:

<div class="grid_6 alpha" id="left-column">				
		<div class="left-column">					
		<h1>Man <span style="color: #FF0">Products</span></h1>
		<p>Our Man Products..</p> <br />
<?php

	//session_start();
	include "admin/sql_comm_helper.php";
	include "admin/sql_data.php";  // File that contains the SQL connection information.
	login_mysql();
	select_db(FALSE);
	$fid = $_POST['fid'];
$data = mysql_query("SELECT * FROM upload WHERE manufacturer='Man'") 
or die(mysql_error()); 
$numberOfRecords = mysql_num_rows($data);

Print "<table border cellpadding=3>";  
for ($i = 1; $i <= ceil($numberOfRecords/2); $i++) {
     $info = mysql_fetch_array( $data )
print "<tr>";  
print '<td><p><img src="download.php?fid='.$info['fid'] . '" width="125" height="125"></td>'; 
print "<td><a href='product.php?fid=".$info['fid'] . "'><span style='font-size: 18px;'>".$info['productname'] ."</span></a></P></td> "; 
}

</div>

print "</table>";
?> 
		</div>	<!--END SERVICES--> 
		
	</div>	<!--END LEFT COLUMN  id="left-column"-->

	
<!--========================================RIGHT COLUMN================================================-->
		<div class="grid_6" id="right-column">
		  <div class="left-column">
		    <h1>&nbsp;</h1>
		    <p>&nbsp;</p>
<br />
		    

<?
while($info = mysql_fetch_array( $data )) {
   print "<tr>";  
print '<td><p><img src="download.php?fid='.$info['fid'] . '" width="125" height="125"></td>'; 
print "<td><a href='product.php?fid=".$info['fid'] . "'><span style='font-size: 18px;'>".$info['productname'] ."</span></a></P></td> "; 
}

</div>
?>
      </div>
		</div>
  <p>
		  <!--END RIGHT COLUMN-->

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jon C

ASKER
Hi

Thanks for your reply again

I have changed the code as you suggested and added the error reporting but it still gives the Internal Server Error

Thanks

Jon
Jon C

ASKER
Sorry, think it was some of my typo errors, here is what worked, thanks to your help:

		<div class="left-column">					
				<h1>Man <span style="color: #FF0">Products</span></h1>
				<p>Our Man Products..</p> <br />
				
				





<?php

	//session_start();
	include "admin/sql_comm_helper.php";
	include "admin/sql_data.php";  // File that contains the SQL connection information.
	login_mysql();
	select_db(FALSE);
	$fid = $_POST['fid'];
$data = mysql_query("SELECT * FROM upload WHERE manufacturer='Man'") 
or die(mysql_error()); 
$numberOfRecords = mysql_num_rows($data);


Print "<table border cellpadding=3>";  
for ($i = 1; $i <= ceil($numberOfRecords/2); $i++) {
     $info = mysql_fetch_array( $data );  
print "<tr>";  
print '<td><p><img src="download.php?fid='.$info['fid'] . '" width="125" height="125"></td>'; 
print "<td><a href='product.php?fid=".$info['fid'] . "'><span style='font-size: 18px;'>".$info['productname'] ."</span></a></P></td> "; 
}  
print "</table>";
?> 

		</div>	<!--END SERVICES--> 
		
	</div>	<!--END LEFT COLUMN  id="left-column"-->

	
<!--========================================RIGHT COLUMN================================================-->
		<div class="grid_6" id="right-column">
		  <div class="left-column">
		    <h1>&nbsp;</h1>
		    <p>&nbsp;</p>
<br />
		    
<?
while($info = mysql_fetch_array( $data )) {
     print "<tr>";  
print '<td><p><img src="download.php?fid='.$info['fid'] . '" width="125" height="125"></td>'; 
print "<td><a href='product.php?fid=".$info['fid'] . "'><span style='font-size: 18px;'>".$info['productname'] ."</span></a></P></td> "; 
}
?>

	      </div>
		</div>
  <p>
		  <!--END RIGHT COLUMN-->

Open in new window

Jon C

ASKER
Many thanks, very detailed help, greatly appreciated, Jon
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Chris Stanyon

No worries, glad I could help.

You might want to check your HTML as well. You have a couple of loose tags. On lines 28 and 49 you have an opening P tag, but no closing P. On lines 29 and 50, you have a closing P tag but no opening one. I'm guessing these are supposed to be a matching pair, but you can't have a P tag span over several <TD>s

Also, the code for the right column is creating TRs and TDs but has no TABLE associated with it.

Good luck with your project :)