Hi,
I created a query which runs perfectly in phpMyAdmin, but when in the php page it gives the "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource..."
My Query is:
SET @row =100;
SELECT STRAIGHT_JOIN ipod2000_muscol_albums.name, ipod2000_muscol_artists.artist_name, ipod2000_muscol_albums.year, SUM( ipod2000_xml_list.list_played ) , ipod2000_muscol_albums.image, ipod2000_muscol_albums.buy_link, @row := @row +1 AS row_number
FROM (
ipod2000_xml_list
INNER JOIN ipod2000_muscol_albums ON list_keywords = ipod2000_muscol_albums.keywords
)
INNER JOIN ipod2000_muscol_artists ON artist_name = list_artist
GROUP BY list_keywords
ORDER BY SUM( list_played ) DESC
LIMIT 100 , 100
The query gets a list of 100 records ordered by number of times played and it adds a ranking (first row: 101, second row: 102, and so on) to it.
The PHP code is:
$result = mysql_query("SET @row =100;
SELECT STRAIGHT_JOIN ipod2000_muscol_albums.name, ipod2000_muscol_artists.artist_name, ipod2000_muscol_albums.year, SUM( ipod2000_xml_list.list_played ) , ipod2000_muscol_albums.image, ipod2000_muscol_albums.buy_link, ipod2000_muscol_artists.letter, @row := @row +1 AS row_number
FROM (
ipod2000_xml_list
INNER JOIN ipod2000_muscol_albums ON list_keywords = ipod2000_muscol_albums.keywords
)
INNER JOIN ipod2000_muscol_artists ON artist_name = list_artist
GROUP BY list_keywords
ORDER BY SUM( list_played ) DESC
LIMIT 100 , 100");
while ($row=mysql_fetch_row($result))
{
print "...
Question:
Isn't it possible to integrate the row numbering (@row := @row +1 AS row_number) in a query on a table?. Is there an other solution?
Many thanks in advance!
Dave