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...

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."'
";

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 ."'
";

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!

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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.