DataTables logo DataTables

via Ad Packs
mysql. Only show values were column value = 0
  • mcflausemcflause
    Posts: 10
    I have an inventory system and for stock that is produced it gets a value of 0 for stock. For stock that is shipped it gets a value of 1 for stock.

    So I want to make it that the table only displays the rows for when stock=0 or stock=1. Is this possible?

    include( "include/db.php" );
    
    $editor = new DTEditor(
    	$db, // DB resource
    	'inventory', // DB table
    	'id', // Primary key
    
  • mcflausemcflause
    Posts: 10
    I just started fiddling around and I figured it out:

    include( "include/db.php" );
     
    $editor = new DTEditor(
        $db, // DB resource
        'inventory WHERE stock = 0', // DB table
        'id', // Primary key
    
  • allanallan
    Posts: 15,493
    Hi mcflause,

    Excellent question - this isn't actually something the the DTEditor classes have built in support for at the moment, but I've added it to the roadmap (with Editor v1.2 these classes will be updated to be a lot more capable and I'll make sure this goes in as a feature).

    Your word around using the DB table field is a nice idea, but I think it will only work for 'get' options and not for adding, editing and removing data which it would result in an SQL error.

    What you could do as a work around (its a bit hackish, but I think it will work nicely for the moment!) is much as you currently have, but only add the extra where condition when not adding, editing or deleting data. For example:

    include( "include/db.php" );
      
    $editor = new DTEditor(
        $db, // DB resource
        !isset($_POST['action']) ? 'inventory WHERE stock = 0' : "inventory", // DB table
        'id', // Primary key
    

    'action' is set when Editor is doing an add, edit or delete, to tell the server what is going on, but is not set when just getting data.

    Regards,
    Allan
This discussion has been closed.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion