web hosting and development forums
Web Design and Development Forums Archive


Index - HTML forum

problems with sql query


Post reply

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 ?
Simple?
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
<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
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 ?
optomeb: you can use LIMIT in your sql query to only fetch the top 30 users
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 ?
How are you storing the data? mySQL?
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.
Yes
You could write a simple SQL statement to do that.
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
Can't say I know off the top of my head what hte SQL is.
At least i know it can be done:)
Do you have a relationship between the referral number and the username?
Yes the refferal number is the userid of that username
Then you just need to use a JOIN statement to join the referral number in one table to the username in another.
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
All doable.
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 :)




Dubai Forum | Paris Forum | Webmaster Forum | Vegan Forum | Brisbane Forum | 3D Forum | Jobs in Dubai | Jobs in London | London UK Classifieds
Archive script by RedHo.com