Forum Moderators: coopster

Message Too Old, No Replies

Sorting data help

         

tresmom5

1:52 am on Feb 21, 2005 (gmt 0)

10+ Year Member



I know this should be fairly easy, but I am still very new at this. Ok, I am trying to pull data from my database and sort it. I want it to sort it by using field one sorting alphabetically, but only pulling up results from field two that has a specific name. I am not explaining this well sorry. I'll give you the code that I am trying and it's not working because I know I am not doing it right.

$result = mysql_query("select * from items where itemName Like'A%' and WHERE field2='value'
order by itemName asc");

Ok, I don't think I can use the and but I don't really know how to do this. Can anyone help?

Teresa

grandpa

2:23 am on Feb 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi. I modified you query slightly. When using LIKE, you should use % before and after the value. The second WHERE has also been removed. The AND in the WHERE clause implies WHERE x AND y.

$result = mysql_query("SELECT* FROM items WHERE itemName LIKE '%$A%" AND field2='$value' ORDER BY itemName asc");

I also modified A and value to represent variables that you would plug into the query. Not sure if you are hard coding these values or using variables in your query.

tresmom5

2:45 am on Feb 21, 2005 (gmt 0)

10+ Year Member



Thanks so much. I knew this couldn't be that difficult.

Teresa