Afternoon everyone, quick question on this fetch query.
<?php
$sql = "SELECT * FROM products ";
if(isset($_POST['Submit'])){
if(empty($_POST['Search'])){
$error = true;
}else{
$searchq = mysql_real_escape_string($_POST['Search']);
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$sql .= "WHERE type LIKE '%$searchq%' or name LIKE '%$searchq%'";
}
} $query = mysql_query($sql) or die(mysql_error());
$sql1 = "SELECT * FROM products ";
if(isset($_GET['q'])){
$categories = mysql_real_escape_string($_GET['q']);
$sql1 .= "WHERE type LIKE '%$categories%'";
} $query1 = mysql_query($sql1) or die(mysql_error());
?>
<?php while ($row = mysql_fetch_array($query) and $row = mysql_fetch_array($query1)) { ?>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><a href="productsview.php<?php echo '?id='.$row['serial']; ?>"><b><?php echo $row['name']?></a></div>
<div class="product_img"><a href="productsview.php<?php echo '?id='.$row['serial']; ?>"><img src="<?php echo $row['picture']?>" height="100" width="120" /></a></div>
<div class="prod_price"><span class="reduce"><?php if($row['rprice'] > 0) {echo "£"; echo $row['rprice'];}?></span> <span class="price"><big style="color:green">£<?php echo $row['price']?></big></span></div>
</div>
<div class="bottom_prod_box"></div>
<div align="center" class="prod_details_tab"> <input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']?>)" /></td> </div>
</div>
<?php } ?></p>
Anyone see anything wrong ere? The query fetches fine but, not properly, it will fetch parts of the other query even when the forms not even submitted. :\
$query
has 5 and$query1
has 10, then 5 products will be displayed, ignoring other 5 from$query1
. – KarelG Mar 6 at 14:45