Forum Moderators: coopster

Message Too Old, No Replies

Problem with Mysql PHP

         

romzinho2k7

7:05 am on Oct 10, 2006 (gmt 0)

10+ Year Member



Hi my friends.

I'm with problem in database. look:

$query = mysql_query("SELECT * FROM images WHERE id_cat="$cat" ORDER BY id_cat DESC");

The database return:

id_cat - name_cat
4 -------- Cars
3 -------- Sport
2 -------- Nature
1 -------- Cars

I make

$query = mysql_query("SELECT * FROM images WHERE id_cat="$cat" GROUP BY name_cat ORDER BY id_cat DESC");

Hide the id_cat 4... I want that he hides id_cat 1.
How I can make this?

OBS: Sorry my english! :)

Thanks

dreamcatcher

9:45 am on Oct 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, you want to return everything except cat 1? Can you not just do:

WHERE id_cat!='1'

Also I`m guessing that having the double quotes in your query line would generate a parse error? Try apostrophes.

dc

whoisgregg

5:04 pm on Oct 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ORDER BY id_cat ASC

Try using ascending instead of descending. :)

romzinho2k7

6:17 am on Oct 12, 2006 (gmt 0)

10+ Year Member



Hi, forgives the delay in answering.

It takes off id the same, using ASC or DESC, is in the same…
I am trying to make a system of that when the user to bring up to date its area, either counter for first, however it is repeating the user. It wanted q showed to only one time each user.

Type favorites of fotolog

Somebody knows the solution?

coopster

7:49 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The GROUP BY clause should handle your grouping for you. When grouping on the name_cat as you did in your query example there is no way you should be receiving duplicates in that column. Double check for odd characters or spaces in that column entry perhaps?

On a side note, when using a GROUP BY you should also GROUP on the non-aggregate function fields in your query. The syntax used is a MySQL extension to the standard. Yes, it will work in MySQL.

[dev.mysql.com...]