olaoyesunday Posted August 4, 2020 Share Posted August 4, 2020 I want my site to search for any product that belonged to particular size when clicked any size option in the select input menu on mobile version like shop by size menu in www.brastop.com on mobile version. My problem is on how to extract size variable from option tag and put it in the select query in sizeresult.php. below are my codes: 1) for select menu <select class="" name="searchsizemobile" onchange="location = this.value;" id=""> <option selected disabled>Select Your size:</option> <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($dbc,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo " <option value='sizeresults.php?$size_id'> $size_name </option> "; } ?> </select> my prolem is how to extract the $size_name from option tag and put it in between the two single quotes after the WHERE CLAUSE on the first line in the next code snipet where I wrote sizes.size = ='%$size_name%' for sizeresult.php <?php $run_products = mysqli_query($dbc,"SELECT * FROM products INNER JOIN SIZES USING (size_id) WHERE sizes.size ='%$size_name%'"); while($row_products=mysqli_fetch_array($run_products)){ $pro_id = $row_products['product_id']; $pro_title = $row_products['product_title']; $pro_price = $row_products['product_price']; $pro_sale_price = $row_products['product_sale']; $pro_url = $row_products['product_url']; $pro_img1 = $row_products['product_img1']; $pro_label = $row_products['product_label']; $manufacturer_id = $row_products['manufacturer_id']; $get_manufacturer = "select * from manufacturers where manufacturer_id='$manufacturer_id'"; $run_manufacturer = mysqli_query($dbc,$get_manufacturer); $row_manufacturer = mysqli_fetch_array($run_manufacturer); $manufacturer_title = $row_manufacturer['manufacturer_title']; if($pro_label == "sale"){ $product_price = " <del> NGN $pro_price </del> "; $product_sale_price = "/ NGN $pro_sale_price "; }else{ $product_price = " NGN $pro_price "; $product_sale_price = ""; } if($pro_label == ""){ }else{ $product_label = " <a href='#' class='label $pro_label'> <div class='theLabel'> $pro_label </div> <div class='labelBackground'> </div> </a> "; } echo " <div class='col-md-4 col-sm-6 center-responsive'> <div class='product'> <a href='$pro_url'> <img class='img-responsive' src='admin_area/product_images/$pro_img1'> </a> <div class='text'> <center> <p class='btn btn-primary'> $manufacturer_title </p> </center> <h3> <a href='$pro_url'> $pro_title </a> </h3> <p class='price'> $product_price $product_sale_price </p> <p class='button'> <a class='btn btn-default' href='$pro_url'> View Details </a> <a class='btn btn-primary' href='$pro_url'> <i class='fa fa-shopping-cart'></i> Add to Cart </a> </p> </div> $product_label </div> </div> "; } ?> Link to comment Share on other sites More sharing options...
olaoyesunday Posted August 5, 2020 Author Share Posted August 5, 2020 I have gotten the solution from stack overflow, the solution is below <form action="sizeresults.php" method="POST"><!-- use post method not must but safe --> <select name="size" onchange="this.form.submit()"> <option selected disabled>Select Your size:</option> <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($dbc,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo "<option value='$size_name'> $size_name </option>"; } ?> </select> add the following line right above $run_products = mysqli_query(... in sizeresults.php file. $size_name=$_POST['size']; Link to comment Share on other sites More sharing options...
Larry Posted August 5, 2020 Share Posted August 5, 2020 Thanks for sharing what you found! Personally, though, I'd still use the GET method here. POST doesn't really make sense in this case. Link to comment Share on other sites More sharing options...
Recommended Posts