Just want to ask help for php programmers. I have a problem alligning my product, actually i'm trying to display the product that's query in mysql display it in two column. here's my code: $left = true; while($fetched=mysql_fetch_array($result)) { if ($left) { echo "<table><tr>"; } echo "<td align='justify' width='35%' cellspacing='2' cellpadding='2' >"; echo "<div class='xdiv' id='xborder'><table width='100%' border='0' cellspacing='0' cellpadding='0'> <tr> <td colspan='2' valign='top' height='20' background='images/bg.jpg' class='whiteBold'><a name=".$fetched['product_name']."></a> ".$fetched['products_name']."<br></td> </tr> <tr> <td width='22%' rowspan='2' valign='top'><img src=".$fetched['product_imagepath']." width='120' height='100' style='border:1px #323335 solid;'></td> <td width='78%' valign='top'><span class='redFont'>Description: </span><span class='normaltext'>".$fetched['product_description']."</span></td> <tr> <td valign='middle'><span class='redFont'>Price: </span><span class='normaltext'>".$fetched['price']."</span></td> </table></div>"; echo"</td>"; if (!$left) { echo"</tr>"; } $left = !$left; } echo"</table>"; PHP: actual output: anyone can debug my code, just want to align the display in two column. please help.. thanks
Well, first off I'd say you are probably using a table for no good reason, second you are using TWO tables for no good reason, and have your 'while' nesting all screwed up. Of course you've made life four or five times more difficult than need be using double quotes in PHP... It also might help if you only want two columns you might want to try using 50% and not 35%. If I wrote that it would probably go something like this: echo ' <div class="productList">'; while($fetched=mysql_fetch_array($result)) { echo ' <div class="product"> <h2 id="product_',urlencode($fetched['product_name']),'">,$fetched['products_name'],'</h2> <img src="',$fetched['product_imagepath'],'" width="120" height="100" /> <p> <span>Description:</span> ',$fetched['product_description'],' </p> <!-- .product --></div> <div class="productPrice"> <span>Price:<span> ',$fetched['price'],' <!-- .productPrice --></div> '; } echo ' <!-- .productList --></div> '; Code (markup): Though it would require an entirely different set of CSS to make it display how you want - productList set to wrap floats, set .product to float:left and width:49%; (don't use 50% or IE will *** it up), your internal product links (name in your version) would have to be changed wherever you are referring to them from to match the ID (since ID is supposed to supplant A NAME in modern markup)... the bottom of the paragraph being bottom padded equal to the line-height then using a negative margin to ride the price up into it. In other words, moving all that table/presentational malarkey the **** out of the markup.