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.
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 :).
Sep 30, 2001, 9:55 PM
Veteran (17240 posts)
Sep 30, 2001, 9:55 PM
Post #4 of 6
Views: 2054
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:
SELECT COUNT(*)
FROM Links
WHERE UserID = 1
========================================
Buh Bye!
Cheers,
Me
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
Oct 1, 2001, 5:05 PM
Administrator (9387 posts)
Oct 1, 2001, 5:05 PM
Post #5 of 6
Views: 2046
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.
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.
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.
- 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.