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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.