Here is as an example of a query that my search form generates:
SELECT uploads.title, uploads.date, COUNT(downloads.ID) AS downloads, COUNT(reviews.ID) AS reviews, SUM(reviews.rank) AS rank, uploads.size, users.username, users.stars FROM uploads WHERE users.username LIKE '%oleg%' AND (uploads.title LIKE '%file%' OR uploads.description LIKE '%file%') AND DATE_SUB(CURDATE(),INTERVAL 31 DAY) <= uploads.date AND uploads.size > '100' and uploads.size <= '300' ORDER BY uploads.title ASC, users
WHERE users.ID = uploads.user_ID, downloads WHERE downloads.file_ID = uploads.ID, rank WHERE rank.file_ID = uploads.ID
Let's i assume i ran this query and got some results, and the result idenifier is now '$result'.
what would be the key of each field after i'll fetch an associated array out of those results?.
I was thinking that it might be just the name of the field, just like in a simple query, but then, there are some fields with the same name in different tables,
so far i didn't had to face this situation in praticular, but i'm sure that mysql
is designed to avoid that situation at all costs.
I also thought the results might be placed in a 2-dimmensional array, where the first key is the table name, and the second is the field name.
Or perhaps the key is just like the filed name, as it appears in the query?
I searched the web for the answer, and sadly, i was unable to find anytihng to answer my question.
I was hoping you can clearify that for me, guys.
I can always use AS after every field i select, but that would be nusty.
Also i'd like to order the results by the results of the query by the result of one of the SUM() or COUNT() functions. and i use the key i gave them with AS.
SELECT uploads.name, COUNT(reviews.ID) AS reviews FROM reviews WHERE
reviews.file_ID = uploads.ID, uploads WHERE uploads.size < 50 ORDER BY reviews
Can i do this?