Skip to main content
Known Participant
January 19, 2007
Question

users who favourited this also favourited this

  • January 19, 2007
  • 14 replies
  • 872 views
hi i am trying to set up a system similar to amazons, whereby when you search a book, it tells you Customers who bought this item also bought these items( a list of other books)
What i am trying to do is have a system which tells you "users who have favourited this musician have also favourited these artists"...
At the moment I have a query which takes an artists primary id from the url of thier page, and the users primary id who favourited the artist, and puts this into a table, so then you can call the users fav artists, using

SELECT *
FROM artists_fav
WHERE id_usr_fav=#SESSION.auth.idnumber#

But im unsure of how to write a query that would take all the other artists that a user has, who has favourited "massive attack" for example, and present this in a list whereby the artist who has been favourited the most by users who have also favourited massive attack is at the top, then the next popular is second etc

here my site

http://www.musicexplained.co.uk/index_artist.cfm?id_art=38


and if you would like to test the favouriting system, you can use username blanko, and password dranko

any help here would be MUCH appreciated
This topic has been closed for replies.

14 replies

namtaxAuthor
Known Participant
January 27, 2007
ok, ill put it in
cheers
Inspiring
January 27, 2007
You forgot the group by clause
namtaxAuthor
Known Participant
January 27, 2007
hi, following your advice i have pretty much got this up and running, the only thing is, that when i try and run the count (bandname_art) as favourite in the query i get an error message

so

<!---similar artists--->
<cfquery name="sim_art" datasource="#APPLICATION.DataSource#">
SELECT bandname_art
FROM artist_art
LEFT OUTER JOIN artists_fav
ON artist_art.id_art = artists_fav.id_artkey_fav
WHERE id_usr_fav IN
(select id_usr_fav
from artists_fav
where id_usr_fav <> #session.auth.idnumber#
AND id_artkey_fav = #url.id_art#)
AND id_art <>#url.id_art#
</cfquery>

is fine

but

<!---similar artists--->
<cfquery name="sim_art" datasource="#APPLICATION.DataSource#">
SELECT bandname_art, count (bandname_art) as favourite_count
FROM artist_art
LEFT OUTER JOIN artists_fav
ON artist_art.id_art = artists_fav.id_artkey_fav
WHERE id_usr_fav IN
(select id_usr_fav
from artists_fav
where id_usr_fav <> #session.auth.idnumber#
AND id_artkey_fav = #url.id_art#)
AND id_art <>#url.id_art#
</cfquery>
returns the error message of "You tried to execute a query that does not include the specified expression 'bandname_art' as part of an aggregate function."

i was wondering there was another way to order by favourite count...maybe by using another query in conjuction etc etc

cheers
namtaxAuthor
Known Participant
January 21, 2007
yes, join doesnt work, but inner join does

ill have a play around with the queries and let you know what happens

cheers
Inspiring
January 21, 2007
I don't work with Access, so I'm guessing. Perhaps you have to use inner join instead of join. Also, Access might not support subqueries in the from clause.

To trouble shoot, see if this works:
SELECT bandname_art, count(bandname_art)as favourite_count
FROM artist_art
JOIN artists_fav
ON artist_art.id_art = f1.artists_fav.id_artkey_fav

That will test the join vs inner join possibility.

If that works, it's probably the subquery. In that case, you can try joining to artists_fav twice. You give them different alias names. Or, you can move the subquery to the where clause.
namtaxAuthor
Known Participant
January 21, 2007
have changed query to this, but still same error message
<cfquery name="sim_art_2" datasource="#APPLICATION.Datasource#">
SELECT bandname_art, count(bandname_art)as favourite_count
FROM artist_art
JOIN artists_fav
ON artist_art.id_art = f1.artists_fav.id_artkey_fav
JOIN
(
SELECT id_usr_fav from artists_fav
WHERE id_usr_fav <> #SESSION.auth.idnumber#
AND f1.id_artkey_fav= #url.id_art#
)
f2 on fl.id_usr_fav = f2.id_usr_fav
</cfquery>

cheers
Inspiring
January 21, 2007
It's the double quotes. If the field is numeric, and id fields should be, you use no quotes. It the field is text, you use single text.
namtaxAuthor
Known Participant
January 21, 2007
hi, have changed my query to

<cfquery name="sim_art_2" datasource="#APPLICATION.Datasource#">
SELECT bandname_art, count(bandname_art)as favourite_count
FROM artist_art
JOIN artists_fav
ON artist_art.id_art = f1.artists_fav.id_artkey_fav
JOIN
(
SELECT id_usr_fav from artists_fav
WHERE id_usr_fav <>"#SESSION.auth.idnumber#"
AND f1.id_artkey_fav="#url.id_art#"
)
f2 on fl.id_usr_fav = f2.id_usr_fav
</cfquery>

but am unfortunately now getting this error message

http://www.musicexplained.co.uk/index_artist_1.cfm?id_art=27&CFID=83776&CFTOKEN=57625191
namtaxAuthor
Known Participant
January 19, 2007
cheers for this, just on way out.....will let you know if this works for me when i try tommorrow, just wanted to say thanks as you have been very helpful in the past on this forum
Inspiring
January 19, 2007
select artist_name, count(artist_name) favourite_count

from artist a join fav on a.artist_id = f1.id_artist_favtable
join
(select id_usr_favtable
from fav
where id_usr_favtable <> "your session number"
and f1.id_artist_favtable = "the one from the url"
) f2 on f1.id_usr_favtable = f2.id_usr_favtable

group by artist_name
order by favourite_count
having favourite_count > some_number