Jump to content

Select problem


Topshed

Recommended Posts

Hi back again ...

 

I have a small problem with Select that has got me confused

 

I am using select to find and occurance of a number  $fnum in either of two fields

$fnum = 111
'
'
'
'
$db="SELECT * FROM $tble WHERE code01 = $fnum OR code02 = $fnum";

 

Simple, well it should be,

the problem is that I occasionaly have 2 similar records

 

                    field1        field2

record X  has    0    and  111

record Z  has  111    and  111

 

and the darn thing returns both unsurprisingly !

 

using AND finds only record Z . but I need to find record X only

and there are over 1000 record with 0 in field1

 

using ASP I have used code that seems to work well

 

strSQL = "SELECT * " _
	& "FROM table" _
	& "WHERE code1 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
	& "OR code2 LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
	& "ORDER BY ID;"

 

 

but I cannot seem to get it working in PHP

 

Please help

 

topshed

 

 

Link to comment
Share on other sites

As you are using OR in the query it will search the entries that have either of the two conditions true.I dont know how you did same in ASP,The query logic should be same.

If i have understood properly,You have the two fields in a table->field1 and field2.

Suppose:

field1  field2

1          2

2          3

1          3

.....

 

then when you write the query:

select * from my_table where fileld1=$value1 OR $field2=$value2.

Imagine what would happen if the value of $value1 was 1 and value of $value2 was 3.Did you get only one entry.If you need to have only one row selected then you should make sure that each row has the combination of field1 and field2 different.That is no two rows can have the same value of field1 and field2 but can have only one of them as same.

Either you should use AND logic in the query, or you wont get through this.

Or if the problem is different then send the table structure .

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.