mysql. Only show values were column value = 0

mysql. Only show values were column value = 0

mcflausemcflause Posts: 10Questions: 0Answers: 0
edited June 2012 in Editor
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?

[code]
include( "include/db.php" );

$editor = new DTEditor(
$db, // DB resource
'inventory', // DB table
'id', // Primary key
[/code]

Replies

  • mcflausemcflause Posts: 10Questions: 0Answers: 0
    edited June 2012
    I just started fiddling around and I figured it out:

    [code]
    include( "include/db.php" );

    $editor = new DTEditor(
    $db, // DB resource
    'inventory WHERE stock = 0', // DB table
    'id', // Primary key
    [/code]
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    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:

    [code]
    include( "include/db.php" );

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

    '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.