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:
Many thanks
Jon
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> </h1>
<p> </p>
<br />
</div>
</div>
<p>
<!--END RIGHT COLUMN-->
Many thanks
Jon
Do you mean two columns within the table, or spread across the two DIVs - left-column / right-column.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
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> </h1>
<p> </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-->
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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> </h1>
<p> </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-->
ASKER
Many thanks, very detailed help, greatly appreciated, Jon
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 :)
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 :)