Jump to content

[SOLVED] simple mysql statement giving error.. can't figure it out.


Dragen

Recommended Posts

Okay, I'm quite tired so I may just be being really dim witted here, but.. what's wrong with this mysql statement?

$sqlsel = "SELECT * FROM times WHERE day = '".$day."' && group = '".$group."' && start = '".$start."'";

 

I've been staring at it for some time and just can't see the problem. Maybe I just need some sleep...

Whenever I try and run it it gives me this error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group = 'Pre-School' && start = '9:30'' at line 1

I just can't see what's wrong...

Link to comment
Share on other sites

the and operator is not && it is 'and' without the quotes of course...

 

actually, i believe it can be done either way. anyway, try this:

$sqlsel = "
        SELECT
                *
        FROM
                times
        WHERE
                day = '".$day."',
                group = '".$group."',
                start = '".$start."'
";

Link to comment
Share on other sites

hmm, i just noticed something. you have 'Pre-School' in your where argument. mysql may not like the '-' in there. try doing this:

$sqlsel = "
        SELECT
                *
        FROM
                times
        WHERE
                day = '". $day ."'
        AND
                group = '". str_replace('-', '\-', $group) ."'
        AND
                start = '". $start ."'
";

Link to comment
Share on other sites

Okay I've sorted the problem... for some reason it didn't like my mysql cell being called group.

I changed the name to sesgroup and it's working fine! perhaps group is a reserved name for something?

I'd be interested to know.

 

Thanks for all the help!

Link to comment
Share on other sites

Okay I've sorted the problem... for some reason it didn't like my mysql cell being called group.

I changed the name to sesgroup and it's working fine! perhaps group is a reserved name for something?

I'd be interested to know.

 

Thanks for all the help!

 

of course! i can't believe i didn't see it before! GROUP is a mysql argument.

http://www.tizag.com/mysqlTutorial/mysqlgroupby.php

 

sorry i didn't recognise that sooner. glad you figured it out bro! don't forget to mark this topic as 'solved'

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.