| View previous topic :: View next topic |
| Author |
Message |
optomeb
Joined: 19 May 2006 Posts: 113
|
| Hi..im trying to do a sql query from my db to select username and how many refferals they have(i have a refferal contest going) and finally figured out the sql query..would it be hard to put that in a table ? |
| |
|
|
|
|
Koplaf
Joined: 28 May 2006 Posts: 130
|
| Simple? |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
I just don't imagine how, because the table would have to be defined by how many users have refferals
And that's always changing |
| |
|
|
Koplaf
Joined: 28 May 2006 Posts: 130
|
<table><caption>Referrals</caption><thead><tr><th>User</th><th>Refferals</th></tr></thead><tbody><tr><td>Koplaf</td><td>9 million</td></tr>....</tbody></table>
Just loop over your result set
You can always do fancy things like pagination, etc |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
The way i figured i'd do it is do a for i=1 to 30 or something and display the 30 first ones..
The 30 users with most refferals, i mean
So i would do the for loop before the table, and after that include the table in the for loop ? |
| |
|
|
montanarry
Joined: 13 May 2006 Posts: 175
|
| optomeb: you can use LIMIT in your sql query to only fetch the top 30 users |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
montanarry, thanks ill look that up right now
I dont even know how to explain this...i should probably ask in #php but in my user tables i dont save how many refferals each user has..only who was the refferer when you signed up
Could i select who was the refferer for each user in the database and somewhat translate that to the username...then select and display the 30 usernames that reffered the most users ? |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| How are you storing the data? mySQL? |
| |
|
|
WarChild
Joined: 24 Feb 2006 Posts: 46
|
| Keep close to the issue please. SQL has nothing to do with HTML. Do I have to create a new forum which will be SQL-related? Gimme a sign if this is needed. |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| Yes |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| You could write a simple SQL statement to do that. |
| |
|
|
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| Well i figured out how to do a sql query that searches the user database and displays the refferal #, i just have to figure out how to translate that to the right username |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| Can't say I know off the top of my head what hte SQL is. |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| At least i know it can be done:) |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| Do you have a relationship between the referral number and the username? |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| Yes the refferal number is the userid of that username |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| Then you just need to use a JOIN statement to join the referral number in one table to the username in another. |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| For example, I (user 1) reffer john (who is user 4). john will have a value in his database called $ref where the value is 1 |
| |
|
|
plantino
Joined: 13 May 2006 Posts: 96
|
| All doable. |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
But i dont have a value that says i reffered john
plantino, the problem is how can i join it if its all in the same database ?
Same table i mean
:) |
| |
|
|
|