Topshed Posted February 15, 2008 Share Posted February 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 15, 2008 Share Posted February 15, 2008 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 . Quote Link to comment Share on other sites More sharing options...
Topshed Posted February 15, 2008 Author Share Posted February 15, 2008 Thank you thank you someone always sees the error in my logic. I must be getting old Fixed 1 var for each field Regards Roy... Quote Link to comment 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.