like problem

This is a discussion on like problem within the MySQL Database forums, part of the Database Forums category; I am new to MYSQL and the solution is probably quite simple. In a php application I am writing, I ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-15-2008
Carolyn Marenger
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 01-15-2008
Ana C. Dent
 
Posts: n/a
Default Re: like problem

Carolyn Marenger <cajunk@marenger.com> wrote in news:d7867$478c40f5
$cf70133e$18160@PRIMUS.CA:

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


SELECT id, surname, useName FROM individuals
WHERE surname LIKE 'M%'
ORDER BY surname, useName ASC
Reply With Quote
  #3 (permalink)  
Old 01-15-2008
Carolyn Marenger
 
Posts: n/a
Default Re: like problem

Ana C. Dent wrote:
> Carolyn Marenger <cajunk@marenger.com> wrote in news:d7867$478c40f5
> $cf70133e$18160@PRIMUS.CA:
>
>> 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
>>

>
> SELECT id, surname, useName FROM individuals
> WHERE surname LIKE 'M%'
> ORDER BY surname, useName ASC


Thanks! It still needs some tweaking, but no error messages any more. :)

Carolyn
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0