joshluv33 Posted August 11, 2008 Share Posted August 11, 2008 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 https://forums.phpfreaks.com/topic/119184-solved-sql-query-with-variable-and-a-number-problems/ Share on other sites More sharing options...
unkwntech Posted August 11, 2008 Share Posted August 11, 2008 Try 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); Link to comment https://forums.phpfreaks.com/topic/119184-solved-sql-query-with-variable-and-a-number-problems/#findComment-613793 Share on other sites More sharing options...
joshluv33 Posted August 11, 2008 Author Share Posted August 11, 2008 This worked perfectly. I should have known to use (). Thanks. Link to comment https://forums.phpfreaks.com/topic/119184-solved-sql-query-with-variable-and-a-number-problems/#findComment-613893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.