NotVeryTechie Posted September 21, 2010 Share Posted September 21, 2010 Hi there I am very new at this and have to unravel someone else's code to make changes. I have the following code: $resultsa = mysql_query("SELECT course_id, course_url, course_name, new_course FROM courses WHERE sa_elearn = 1 ORDER BY course_name ASC") I would like to select WHERE sa_elearn = 1 and WHERE sa_prod = 1 (show both). I have tried using OR and AND and a comma (e.g. WHERE sa_elearn = 1 OR sa_prod = 1), with and without brackets, but it is not working - it just shows the results from sa_elearn = 1 and not the second one. I am using mySQL 5.0 I know this is very basic but really hope someone will help Thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/ Share on other sites More sharing options...
Miss_Rebelx Posted September 21, 2010 Share Posted September 21, 2010 Did you try running your query directly through the database (via PHPMyAdmin for example) to see if the query itself is working? So you said you tried: $resultsa = mysql_query("SELECT course_id, course_url, course_name, new_course FROM courses WHERE sa_elearn = 1 AND sa_prod = 1 ORDER BY course_name ASC"); Curiously is the sa_prod field a numeric type field or a string field? (ex: int instead of varchar) Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1113745 Share on other sites More sharing options...
NotVeryTechie Posted September 21, 2010 Author Share Posted September 21, 2010 Hi there I hope I don't sound dumb now - I am running the code through our website server, it is part of a php code page that references the database on the server. The values for both these fields can be 0 or 1. I tried AND and OR and a comma and each time it returns the values for sa_elearn, but not for sa_prod. Thank you for the help Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1113748 Share on other sites More sharing options...
kickstart Posted September 21, 2010 Share Posted September 21, 2010 Hi Using OR should work. Only realistic thing I can suggest other than what Miss_Rebelx has already said is that the front end you are using is limiting the number of returned rows. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1113780 Share on other sites More sharing options...
NotVeryTechie Posted September 22, 2010 Author Share Posted September 22, 2010 Thank you kickstart. Is it possible to tell me where to look (is it the php code of the page?). As I said, I need to make changes to the website and (with very little php and mysql knowledge) I am trying to unravel what the guy did that built this thing and trying to make changes. I know this is not the ideal way to do things, but I really need to make it work. When I use the OR, do I need to put the statement in brackets? As in (sa_elearn OR sa_prod), or does that not make a difference? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1113998 Share on other sites More sharing options...
NotVeryTechie Posted September 22, 2010 Author Share Posted September 22, 2010 I got it to work! I carefully went through the code again and used OR inside brackets. Thanks for the help with this. One other thing - every time I save this file, it is creating a second file with a .lck extension. How can I stop the system from doing this? I am using notepad to edit the files. Thanks to all for the help Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1114089 Share on other sites More sharing options...
kickstart Posted September 22, 2010 Share Posted September 22, 2010 Hi The brackets in that situation shouldn't make a difference. You use brackets to force the order that AND and OR statements are executed in rather than the default order, but with only an OR it shouldn't be relevant As to the .lck, not sure but sounds like some kind of locking file. I would suggest you try Notepad++ which is free and very good (others may have their own favourite editor). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1114151 Share on other sites More sharing options...
NotVeryTechie Posted September 27, 2010 Author Share Posted September 27, 2010 Thank you so much for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/214014-very-basic-coding-question/#findComment-1116237 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.