Topshed Posted October 3, 2011 Share Posted October 3, 2011 MySQL client version: 5.1.56 PHP Version information: 3.4.4 I am in trouble with a query The normal one which I use is like this, The idividual scrips are for Gallery Pages to populate the detailed notes with each image so the vars are to fine the record All 3 fields have approx 50% zeros So I enter the numbers where they exist and leave zeros where they don't.. $tble = 'table3'; $a1_num = '12345'; // 5 Medium int can be 0 to 99999 $b1_num = '2001'; // 4 Samll int can be 0 to 9999 $c1_pregr = ' 0'; // 4 Samll int can be 0 to 9999 $db="SELECT * FROM `$tble` WHERE `a1#` = '{$a1_num}' OR 'b1#' = '{$B1_num}'" ; $result = mysqli_query($connect,$db) or die(mysqli_error($connect)); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { etc......... Unfortunately field b1# has some duplicate numbers only 20 or so but when one occurs it finds the first one and of course I often want the second one. To fix this I tried to utilize the third field c1# which should fix my problem but I cannot get it to work None of thefollowing variants work giving me "Query returned 0 results. " $db="SELECT * FROM `$tble` WHERE `b1#` = '{$b1_num}' AND 'c1#' = '{$c1_num}'" ; $db="SELECT * FROM `$tble` WHERE `a1#` = '{$a1_num}' AND 'b1#` = '{$b1_num}' AND c1#' = '{$c1_num}'" ; My preferred Varient would be to query all 3 fields would be most welcomeplease Roy... Quote Link to comment https://forums.phpfreaks.com/topic/248323-nede-help-with-select-where/ Share on other sites More sharing options...
Muddy_Funster Posted October 3, 2011 Share Posted October 3, 2011 could you post a sample dataset? and a breakdown of what each field is being used to store? Quote Link to comment https://forums.phpfreaks.com/topic/248323-nede-help-with-select-where/#findComment-1275162 Share on other sites More sharing options...
awjudd Posted October 3, 2011 Share Posted October 3, 2011 Your query is wrong ... using ' instead of `. $db="SELECT * FROM `$tble` WHERE `b1#` = '{$b1_num}' AND`c1#` = '{$c1_num}'" ; $db="SELECT * FROM `$tble` WHERE `a1#` = '{$a1_num}' AND `b1#` = '{$b1_num}' AND `c1#` = '{$c1_num}'" ; ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248323-nede-help-with-select-where/#findComment-1275210 Share on other sites More sharing options...
Topshed Posted October 5, 2011 Author Share Posted October 5, 2011 Thank you both for your input. Judster you got it in one An instant fix no less I am very grateful Regards Roy.. Quote Link to comment https://forums.phpfreaks.com/topic/248323-nede-help-with-select-where/#findComment-1275840 Share on other sites More sharing options...
awjudd Posted October 5, 2011 Share Posted October 5, 2011 Please mark this thread as resolved. Thanks, ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248323-nede-help-with-select-where/#findComment-1275848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.