like problem
I am new to MYSQL and the solution is probably quite simple. In a php
application I am writing, I am trying trying to write a query to select
all record beginning with an initial, in this case the letter M.
PHP CODE:
-----
$query = "SELECT id, surname, useName FROM individuals ORDER BY surname,
useName ASC WHERE surname LIKE '" . $initial . "%'" ;
$result = mysql_query($query, $link) or die ('<br />Error in query: ' .
$query . '<br />' . mysql_error());
-----
When I run the page, I get an error message reporting a SQL syntax error
with the query.
Error message:
-----
Error in query: SELECT id, surname, useName FROM individuals ORDER BY
surname, useName ASC WHERE surname LIKE 'M%'
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 'WHERE
surname LIKE 'M%'' at line 1
-----
When I copy & paste the query into phpmyadmin, I get the same message.
When I use the phpadmin query panel to create the query, it works.
Any suggestions?
Thanks,
Carolyn
|