HowdeeDoodee Posted June 22, 2007 Share Posted June 22, 2007 This Select statement worked in phpMyAdmin but... SELECT * FROM View2_Concord WHERE (Source = ( 'BZ' ) OR Source = ( 'TX' ) OR Source = ( 'NV' )) AND (Topic LIKE '%power%' OR Subtopic LIKE '%EditWaldron2%' OR Theswords LIKE '%EditWaldron3%') ORDER BY Lnum ASC LIMIT 0 , 30 When I tried to convert the above syntax to the query below... $query2 = "SELECT * FROM View2_Concord WHERE $fieldName1 LIKE '%$SeeAlso1%' OR $fieldName2 LIKE '%$SeeAlso2%' OR $fieldName3 LIKE '%$SeeAlso3%' AND ((Source = $SourceNV) OR (Source = $SourceTR) OR (Source = $SourceBT)) ORDER BY Lnum ASC"; I got this stinking error message. Unknown column 'NV' in 'where clause' NV is not a column. NV is a value in the Source field. Then I tried another query... $query = "SELECT * FROM View2_Concord WHERE (Source = ($SourceNV) OR Source = ($SourceTR) OR Source = ($SourceBT)) AND ($fieldName1 LIKE '%$SeeAlso1%' OR $fieldName2 LIKE '%$SeeAlso2%' OR $fieldName3 LIKE '%$SeeAlso3%') ORDER BY Lnum ASC"; And on this query I got this stinking error message... ...error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (Topic LIKE '%power%' OR Subtopic LIKE '%EditWaldron2%' OR Theswords LIKE' at line 1 Could anyone please give me guidance on cleaning up the syntax? Thank you in advance for any help. :'( Quote Link to comment https://forums.phpfreaks.com/topic/56691-solved-need-help-with-stinking-errors-in-select-statement/ Share on other sites More sharing options...
Illusion Posted June 22, 2007 Share Posted June 22, 2007 try this SELECT * FROM View2_Concord WHERE Source = 'BZ' OR Source = 'TX' OR Source = NV' AND Topic LIKE '%power%' OR Subtopic LIKE '%EditWaldron2%' OR Theswords LIKE '%EditWaldron3%' ORDER BY Lnum LIMIT 0 , 30 as OR operator evaluated first no need to specify the parenthesis and it is default to ASC no need to specify it. Quote Link to comment https://forums.phpfreaks.com/topic/56691-solved-need-help-with-stinking-errors-in-select-statement/#findComment-280018 Share on other sites More sharing options...
HowdeeDoodee Posted June 23, 2007 Author Share Posted June 23, 2007 Thank you for the comment. After a day of continual trials and errors, this is the Select statement I found that will work. The statement requires parenthesis to pull up records accurately. However, there is only one problem. In the following statement, where you see '%power%' I want to substitute a string variable names like $SeeAlso1, $SeeAlso2, and $SeeAlso3. The problem I am having is that when I use a string variable in place of the actual item to be found in the db, I get an error message saying I am not using the right syntax or that I am looking for a column that does not exist. If I use this... $SeeAlso2 = "%power%"; I get the error messages. Here is a query that runs fine because I have the actual values to be found inserted in the query. $query = "SELECT * FROM `View2_Concord` WHERE (`Source` = $SourceNV OR `Source` = $SourceTR OR `Source` = $SourceBT) AND (`Topic` LIKE '%power%' OR `Subtopic` LIKE '%power%' OR `Theswords` LIKE '%power%') ORDER BY `Lnum` ASC"; How do I set up the $SeeAlso varibles so I have the right syntax on the right side of the = sign? Here is the Select statement as I want it to be if I can get the snytax right or the values to insert properly in the $SeeAlso variables. $query = "SELECT * FROM `View2_Concord` WHERE (`Source` = $SourceNV OR `Source` = $SourceTR OR `Source` = $SourceBT) AND (`Topic` LIKE $SeeAlso1 OR `Subtopic` LIKE $SeeAlso2 OR `Theswords` LIKE $SeeAlso3) ORDER BY `Lnum` ASC"; Thank you in advance for any replies. Quote Link to comment https://forums.phpfreaks.com/topic/56691-solved-need-help-with-stinking-errors-in-select-statement/#findComment-280765 Share on other sites More sharing options...
HowdeeDoodee Posted June 23, 2007 Author Share Posted June 23, 2007 This is a followup comment and a remark about how I solved this issue. $query2 = "SELECT * FROM `View2_Concord` WHERE (`Source` = $SourceNV OR `Source` = $SourceTR OR `Source` = $SourceBT) AND ($fieldName1 LIKE '%$SeeAlso1%' OR $fieldName2 LIKE '%$SeeAlso2%' OR $fieldName3 LIKE '%$SeeAlso3%') ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; The last syntax issue regarding $SeeAlso values not being passed into the query statement was caused by how the $SeeAlso variables were written in the query. The above query is currently working properly. Notice the $SeeAlso variables are enclosed in single quotes. I had left out single quotes in writing the query. Thank you to Illusion for the post on this thread to try and resolve this issue. Quote Link to comment https://forums.phpfreaks.com/topic/56691-solved-need-help-with-stinking-errors-in-select-statement/#findComment-280961 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.