Hello Friends how are you ? Please try to solve my problems. how i can display result in two columns using php and my sql. for example, in this way. ASP Progamming C Programming PHP Progamming C++ Progamming Java Programming JSP Programming I have used below code that displayed result in single columns. for example <?PHP include 'library/config.php'; nclude 'library/opendb.php'; echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'>"; $query=mysql_query("select *from programmiong") or die("Error Occured,plz try again"); while($row=mysql_fetch_array($query)) { echo "<tr>"; echo "<td align='justify' width='100%' cellspacing='2' cellpadding='2' >"; echo $row['description']; echo"</td>"; echo"</tr>"; } echo"</table>"; ?> OutPut ASP Progamming PHP Progamming Java Programming C Programming C++ Progamming JSP Programming Please try to modify above code . I am waiting for replys.plz give ur logic and suggestions. Thanks,
Try this: <?PHP include 'library/config.php'; nclude 'library/opendb.php'; echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'>"; $query=mysql_query("select *from programmiong") or die("Error Occured,plz try again"); $left = true; while($row=mysql_fetch_array($query)) { if ($left) { echo "<tr>"; } echo "<td align='justify' width='100%' cellspacing='2' cellpadding='2' >"; echo $row['description']; echo"</td>"; if (!$left) { echo"</tr>"; } $left = !$left; } echo"</table>"; ?>
Hi, I have a My Sql database containing product information that I need to display on a website. I want the items information to show up side by side in 5 columns at 200 pixels each. I have found this forum thread about getting results in two columns. Have tried removing the /tr tag but all that does is load my resuts side by side indefinately. I did try and do something where every fifth record a /tr tag is added but wasn't paticularly successful. Here's the code. <?php // Dynamically Generates Products // Address error handling. ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // Connect and select. if ($dbc = @mysql_connect ('localhost', 'root', 'root')) { if (!@mysql_select_db ('Route69')) { die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>'); } } else { die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>'); } // Define the query. echo "<table border='0' width='1024px' cellspacing='5' cellpadding='0'>"; echo "<tr>"; $query=mysql_query("select *from products WHERE (product_category='Hotrod Zombie Ts') ORDER BY item_no ASC LIMIT 5") or die("Error Occured,plz try again"); $go=true; $one = false; $two = false; $three = false; $four = false; $five = false; while($row=mysql_fetch_array($query)) { if ($go) echo "<td align='justify' width='100%' cellspacing='2' cellpadding='2' >"; echo "<b>{$row['Product_Name']}<br/></b> <img src=\"{$row['Product_Image']}\" alt='{$row['Product_Name']}' width='200' height='150'/><br/> {$row['Product_Code']}<br/> {$row['Product_Sizes']}<br/> {$row['Product_Price']}<br/> {$row['Product_Desc']}<br/> {$row['Product_Category']}<br/></td>"; !$one = $one; } if ($one) { $one = !$one; !$two = $two; $col++; } if ($two) { $two = !$two; !$three = $three; $col++; } if ($three) { $three = !$three; !$four = $four; $col++; } if ($four) { $four = !$four; !$five = $five; $col++; } if ($five) { $five = !$five; $col++; } if ($col==5) {echo"</tr>"; $col=0; !$one = $one; } echo"</table>"; mysql_close(); ?> Code (markup): Please help someone! lol Stuart
Great stuff! I just found this thread very helpful today. Was working on a simple project and needed to display items on a two column table. Good call.
you can try this one... <?php include 'library/config.php'; include 'library/opendb.php'; echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'>"; $query=mysql_query("select *from programmiong") or die("Error Occured,plz try again"); echo "<tr>"; $cell_ctr = 0; while($row=mysql_fetch_array($query)) { if(($cell_ctr % 2) == 0) // 2 is the number of columns { echo"</tr>"; echo "<tr>"; $cell_ctr = 0; } echo "<td align='justify' width='100%' cellspacing='2' cellpadding='2' >"; echo $row['description']; echo "</td>"; $cell_ctr++; } if($cell_ctr == 1) { echo '<td></td>'; echo "</tr>"; } else if($cell_ctr == 2) { echo "</tr>"; } echo"</table>"; ?> PHP:
Cheers, script works great thanks. How can you paginate this to only show 100 results per page with links to sub pages?
https://code.tutsplus.com/tutorials/how-to-paginate-data-with-php--net-2928 Quick and easy tut on how to paginate