Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Number of links owned

Quote Reply
Number of links owned
This is probably not complicated, but I searched the forums and don't see it. I want to search and sort by the number of links owned by a linkowner. There doesn't appear to be a column in the users table that stores this info. If I add a column to users called Num_Links, how do I get this number into it? Thanks in advance.
Quote Reply
Re: [cco] Number of links owned In reply to
Add the following SQL statement in your add.cgi script:

Quote:

UPDATE Users
SET Num_Links = Num_Links + 1
WHERE UserID = $USER->{UserID}

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [AnthroRules] Number of links owned In reply to
Thanks for the reply, Eliot. Won't this solution just affect new links? I don't see how will this count the links each user currently has? When I list all users, I see a number in brackets like this: Links (4). This would seem to indicate that the number of links for each user is stored somewhere in the database. You're dealing with a novice here - be kind :).
Quote Reply
Re: [cco] Number of links owned In reply to
Yes, this will only affect new links added in the databse.

Depending on how many links are associated with Link Owners in your database, you can manually update the Num_Links field/column by counting the number of links associated with each link owner by running the following SQL statement in the SQL Monitor for the Links table:

Quote:

SELECT COUNT(*)
FROM Links
WHERE UserID = 1

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [cco] Number of links owned In reply to
Hi,

The only way to do this is to enter in a raw sql query. You would need to enter into SQL Monitor (under Database menu):

SELECT Username, COUNT(*) AS LinksOwned
FROM Users, Links
WHERE Username = LinkOwner
GROUP BY LinkOwner
ORDER BY LinksOwned DESC

You may need to change FROM Users,Links to include your table prefix.

Hope this helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Number of links owned In reply to
Thanks Alex. I was able to query the database and get a list of users in descending order of links owned. I've created a column in the Users table called Num_Links. Two questions:

- Is there any way to get the numbers I see in the query into the Num_Links field without entering them manually?

- Eliot gave me some code above to insert into my add.cgi script to automate the process in the future. Where exactly in the script do I insert this code?

Thanks in advance.