0

Hello. I have a sorting list which is populated with the different "types" and when a "type" is chosen the images along with corresponding info should be displayed but instead the page is blank with no error. I have another sorting which is more or less the same for sorting price/ascending/descending and these gets displayed but like i said the coding is sort of the same so i dont get why its not working.

this list

<?php 
  $stmt = $conn->prepare("SELECT DISTINCT type FROM tbl");
  $stmt->execute();
  $result = $stmt->fetchAll();
?>
<ul class="dropdown-menu" style="width: 100%;">
<?php foreach($result as $readrow) { ?>
   <li><a href="test.php?type=<?php echo $readrow['fld_product_type']; ?>"><?php echo $readrow['fld_product_type']; ?></a></li>                  <?php
   }
   $conn = null;
?>
</ul>

the select and html:

if(isset($_GET["type"])){
   $gettype = $_GET["type"];
   $stmt = $conn->prepare("SELECT * FROM tbl WHERE type = :cat");
   $stmt->bindParam(':cat', $gettype, PDO::PARAM_STR);
   $stmt->execute();
   $result = $stmt->fetchAll();
?>

<?php foreach($result as $readrow) { ?>
  <div class="col-sm-4 col-lg-4 col-md-4">
     <div class="thumbnail" >
         <?php if ($readrow['img'] == "" ) { ?>
            <img src="products/noimage.jpg" class="img-responsive">
              <?php } else { ?>
                <img src="products/<?php echo $readrow['img'] ?>" class="img-responsive">
              <?php } ?>

              <div class="caption" >
                <h3><?php echo $readrow['id']; ?></h3>
                <p style="height: 90px;">
                  <strong>Name : </strong><?php echo $readrow['name']; ?><br>
                  <strong>Price :</strong> RM<?php echo $readrow['price']; ?><br>
                  <strong>Brand : </strong> <?php echo $readrow['type']; ?><br>
                </p>
              </div>
        <a href="products_details.php?pid=<?php echo $readrow['id']; ?>" class="btn btn-primary btn-block" role="button">View</a>
      </div>
   </div>
<?php } $conn = null; ?>

so the html bit is to display so sorting and all other else uses it. the only difference is the select and list part. the select statements are in if elseif statements.

2
Contributors
2
Replies
14
Views
4 Weeks
Discussion Span
Last Post by random_1
0

Type is a reserved word in MySql so this line

$stmt = $conn->prepare("SELECT DISTINCT type FROM tbl");

will be failing. You need to quote the word type for it to be treated as a column name.

$stmt = $conn->prepare("SELECT DISTINCT 'type' FROM tbl");

0

actually its fld_product_type, so the reserved word ides doesn't apply. though thats a tiny bit info i didn't know. you learn new things everyday! thanks anyway.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.