Jump to content

Very basic coding question


NotVeryTechie

Recommended Posts

 

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  :shy:

 

Thanks so much

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.