Jump to content

[SOLVED] SQL Query with variable and a number. Problems


joshluv33

Recommended Posts

I am trying to use the following query

 

$ca_result = mysql_query("SELECT * FROM print_options where child = '$x' AND print_id = $print_id order by objorder", $db);

 

to display specific options to be displayed to the client.  This works great because the $print_id is sent from another page with no problem.  What I need to accomplish though, is to be able to use the above query and to also show all db entries where the print_id = 0.  So for instance, if the $print_id = 1, then all the options with print_id = 1 will display, but at the same time I need the options with print_id = 0 to display.  So the client will always see options with print_id = 0, but the $print_id will vary and change certain options.

 

I have tried something like this:

 

$ca_result = mysql_query("SELECT * FROM print_options where child = '$x' AND print_id = $print_id OR print_id = '0' order by objorder", $db);

 

but this seems to display all of the options including ones where print_id =1,2,3...etc.  I've also tried this:

 

$ca_result = mysql_query("SELECT * FROM print_options where child = '$x' AND print_id = $print_id AND print_id = '0' order by objorder", $db);

.

 

This returns no results, frankly because the print_id can't equal a number and 0 at the same time in the query.  I just don't know if this is possible or not.  Thanks in advance for any help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.