Jump to content

Nede help with Select WHERE


Topshed

Recommended Posts

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

Link to comment
Share on other sites

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

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.