1

I need to apply WHERE status!='disable' in my php code at $result after I click on the checkbox and then on uncheck of the checkbox it should be removed again and both enable and disable datas from MySql should be shown in the php, is that possible without using AJAX codes, if it is then how can I do that. Can anyone find where am I going wrong

Checkbox, code given below:

<h4 id="CATEGORIESfilters">Availability</h4>
<table border="0" cellspacing="0" id="Availabilitytable">
    <tr>
        <td>
            <input type="checkbox" name="Availability" id="Availabilitycheckboxexcludeoutofstock" >
        </td>
        <td>
            <label for="Availabilitycheckboxexcludeoutofstock">Exclude Out Of Stock</label>
        <td>
    </tr>
</table>

Php Code is given below:

<?php
    include "db_connection.php";
    if(isset($_REQUEST['Availability']))
    {
        $availability="WHERE status!='disable'";
    }
    else
    {
        $availability="";
    }
    $result = mysql_query("SELECT * FROM burger $availability ORDER BY product_no_id DESC");
    while($data=mysql_fetch_array($result)):
    if($data['status']=="enable")
    {
?>
<div class="productwrap">
    <div id="Instockwrap">
            In Stock
    </div>
</div>
<?php
    }
    else
    {
?>
<div class="productwrap">
    <div id="Outofstockwrap">
            Out Of Stock
    </div>
</div>
<?php
    }
    endwhile;
?>
Hardik Sisodia
  • 615
  • 3
  • 14
  • 37
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 02 '15 at 11:25
  • @JayBlanchard Is [prepared statement](https://en.wikipedia.org/wiki/Prepared_statement) a whole new concept for applying mysql_* and by using PDO how can I solve my above query? I've no clue about it, Thanks for updating me with this information will surely give it a try. – Hardik Sisodia Jul 02 '15 at 12:47
  • What you're asking above is not possible without a redirect or AJAX. Prepared statements serve a number of purposes, not the least of which is protecting your code from SQL injection attacks. – Jay Blanchard Jul 02 '15 at 12:48

1 Answers1

1

you can add a class to the out of stock items and hide them via jquery if checkbox is checked, so you dont have to reload the page on checkbox changes

  • [It's not hard to earn enough rep to make comments.](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead) – Jay Blanchard Jul 02 '15 at 11:34
  • @dem4rc Well you are not wrong on your point but if I do that the further out of stock products which will be in while loop would still be visible, that is only the first out of stock product will be removed whereas rest would still be there visible on the page – Hardik Sisodia Jul 02 '15 at 19:02