Advertisement
cdsatrian

list product

Sep 3rd, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <!doctype html>
  2. <head>
  3. <title>product</title>
  4. <style type="text/css">
  5. span.row {
  6.  display: table-row;
  7. }
  8. div.box {
  9.  border:dashed 1px #eee;
  10.  text-align:center;
  11.  width:200px;
  12.  height:50px;
  13.  display: table-cell;
  14.  padding:2px;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <?php
  20. $id=isset($_GET['id'])?$_GET['id']:'';
  21. $db=new mysqli('localhost', 'my_user', 'my_password', 'my_db');
  22. if (mysqli_connect_error()) {
  23.     die('Connect Error ('.mysqli_connect_errno().')'.mysqli_connect_error());
  24. }
  25. $qry="SELECT * FROM tbl_product".($id?" WHERE category_id='$id'":"");
  26. if($data=$db->query($qry)){
  27.   $i=1;
  28.   echo "<span class=\"row\">\n";
  29.   while ($obj = $data->fetch_object()) {
  30.     echo ($i%3==0?"</span>\n<span>\n":"")
  31.        ."<div class=\"box\"><img src=\"".$obj->product_image."\" alt=\"".$obj->product_title."\">"
  32.        ."<br>".$obj->product_price
  33.        ."</div>\n";
  34.     $i++;
  35.   }
  36.   echo "</span>\n";
  37.   $data->close();
  38. }
  39. $db->close();
  40. ?>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement