I am trying to display information from a db into a table. Basically there are 12 rows for each service. I want each service to have a column beside each other. However at the moment it displays the 12 rows then the next services 12 rows under the previous. Any ideas? <table width="780" cellpadding="3" cellspacing="3" id='id_of_table' > <tr><td width="50"><td width="50"><? if ($mf['company'] == "Shipito") { echo '<img src="images/shipito_small.png">'; } else if ($mf['company'] == "myus"){ echo '<img src="images/myus_small.gif">'; } ?></td></tr> <tr><td width="50"><?=$mf['service']?></tr> <tr><td width="50">$<?=$mf['setup']?></tr> <tr><td width="50">$<?=$mf['monthly']?></td></tr> <tr><td width="50">$<?=$mf['annual']?></td></tr> <tr><td width="50">$<?=$mf['mailoutp']?></td></tr> <tr><td width="50">$<?=$mf['mailoutl']?></td></tr> <tr><td width="50"><?=$mf['shopper']?></td></tr> <tr><td width="50"><? if ($mf['receivep'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><? if ($mf['receivel'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><? if ($mf['consolidation'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><?=$mf['consolidationfeeperpackage']?></tr> <?php } ?> </table> PHP:
have to assume this is in the while loop. add table tag and <tr> before the while loop before the table starts in the above code put <td> at the end put </td> after the while loop put in the closing </tr> and </table> so this :
Well you have a container table with one row and n columns (where n is the number of services). Then put the PHP in that table, creating a new table within each <TD>. In other words, the final outputted HTML would be something along the lines of: <table id='container'> <tr> <td id='service_1_holder'> <table id='service_1_holder'> <tr><td>Info 1</td></tr> <tr><td>Info 2</td></tr> <tr><td>Info ...</td></tr> <!--And So On--> <tr><td>Info 12</td></tr> </table> </td> <td id='service_2_holder'> <table id='service_2_holder'> <tr><td>Info 1</td></tr> <tr><td>Info 2</td></tr> <tr><td>Info ...</td></tr> <!--And So On--> <tr><td>Info 12</td></tr> </table> </td> <td id='service_3_holder'> <table id='service_3_holder'> <tr><td>Info 1</td></tr> <tr><td>Info 2</td></tr> <tr><td>Info ...</td></tr> <!--And So On--> <tr><td>Info 12</td></tr> </table> </td> </tr> </table> HTML: Your PHP script just fills the right values in the right places. If you can't be bothered to do it manually then you could always loop it
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Compare US Mail Forwarding Services</title> <link rel="stylesheet" type="text/css" href="style.css"/> <script> function show_hide_column(col_no, do_show) { var stl; if (do_show) stl = 'block' else stl = 'none'; var tbl = document.getElementById('id_of_table'); var rows = tbl.getElementsByTagName('tr'); for (var row=0; row<rows.length;row++) { var cels = rows[row].getElementsByTagName('td') cels[col_no].style.display=stl; } } </script> </head> <body> <div id="container"> <div id="header"> <a href="/">US Mail Forwarding</a> </div> <div id="menu"> <a href="/">Home</a> <a href="compare.html">Compare Providers</a> </div> <div id="main2"> <div id="text2"> <b>Compare the different Providers</b><p> We have compared the main 2 providers below and will be adding more providers in the near future. If you have a provider you would reccomend please be in touch so we can add them here! <p> <? $result = mysql_query("SELECT * FROM mf"); ?> <?php while ($mf = mysql_fetch_array($result)) { ?> <table id='container'> <tr> <td id='service_1_holder'> <table id='service_1_holder'> <tr><td width="50"><td width="50"><? if ($mf['company'] == "Shipito") { echo '<img src="images/shipito_small.png">'; } else if ($mf['company'] == "myus"){ echo '<img src="images/myus_small.gif">'; } ?></td></tr> <tr><td width="50"><?=$mf['service']?></tr> <tr><td width="50">$<?=$mf['setup']?></tr> <tr><td width="50">$<?=$mf['monthly']?></td></tr> <tr><td width="50">$<?=$mf['annual']?></td></tr> <tr><td width="50">$<?=$mf['mailoutp']?></td></tr> <tr><td width="50">$<?=$mf['mailoutl']?></td></tr> <tr><td width="50"><?=$mf['shopper']?></td></tr> <tr><td width="50"><? if ($mf['receivep'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><? if ($mf['receivel'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><? if ($mf['consolidation'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } ?></td></tr> <tr><td width="50"><?=$mf['consolidationfeeperpackage']?></tr> </table> </td> </table> <?php } ?> </div> <form> Enter column no: <input type='text' name=col_no> <br> <input type='button' onClick='javascript:show_hide_column(col_no.value, true);' value='show'> <input type='button' onClick='javascript:show_hide_column(col_no.value, false);' value='hide'> </form> <div class="clear"></div> </div> <div id="footer"> </body> </html> PHP: Thats what I have at the moment but it is still the same problem¬. thanks for your help!
Fixed it up for you. For anyone who is wondering, I just changed the while(); loop and since tables are being used, I used a table within a table. That's just for the visual setup. The sorting can be done via a $_GET var as long as it's properly secured and can simply append the query. E.g.: Sort by price: url.php?price=10 will cause the query to WHERE price <= mysql_real_escape_string($_GET['price']) then only results with a price matching that amount or less than that will be displayed. But I have to run to work right now or I'd finish it up for you. <?php $result = mysql_query("SELECT * FROM mf"); print "<table id='container'><tr>"; while ($mf = mysql_fetch_array($result)) { print "<td><table><tr><td>"; if ($mf['company'] == "Shipito") { echo '<img src="images/shipito_small.png">'; } else if ($mf['company'] == "myus"){ echo '<img src="images/myus_small.gif">'; } print "</td></tr><tr><td>{$mf['service']}</tr><tr><td>\${$mf['setup']}</tr>". "<tr><td>\${$mf['monthly']}</td></tr><tr><td>\${$mf['annual']}</td></tr>". "<tr><td>\${$mf['mailoutp']}</td></tr>". "<tr><td>\${$mf['mailoutl']}</td></tr>". "<tr><td>{$mf['shopper']}</td></tr>". "<tr><td>"; if ($mf['receivep'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } print "</td></tr><tr><td>"; if ($mf['receivel'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } print "</td></tr><tr><td>"; if ($mf['consolidation'] == "n") { echo '<img src="images/no.gif">'; } else { echo '<img src="images/tick.png">'; } print "</td></tr><tr><td>\${$mf['consolidationfeeperpackage']}</td></tr></table></td>"; } ?> </tr></table> PHP: Regards, Dennis M.