redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

problems with sql query



 
Post new topic   Reply to topic    Web Design Forums -> HTML forum
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 ?
  Reply with quote


Koplaf



Joined: 28 May 2006
Posts: 130
Simple?
  Reply with quote
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
  Reply with quote
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
  Reply with quote
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 ?
  Reply with quote
montanarry



Joined: 13 May 2006
Posts: 175
optomeb: you can use LIMIT in your sql query to only fetch the top 30 users
  Reply with quote
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 ?
  Reply with quote
plantino



Joined: 13 May 2006
Posts: 96
How are you storing the data? mySQL?
  Reply with quote
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.
  Reply with quote
optomeb



Joined: 19 May 2006
Posts: 113
Yes
  Reply with quote
plantino



Joined: 13 May 2006
Posts: 96
You could write a simple SQL statement to do that.
  Reply with quote


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
  Reply with quote
plantino



Joined: 13 May 2006
Posts: 96
Can't say I know off the top of my head what hte SQL is.
  Reply with quote
optomeb



Joined: 19 May 2006
Posts: 113
At least i know it can be done:)
  Reply with quote
plantino



Joined: 13 May 2006
Posts: 96
Do you have a relationship between the referral number and the username?
  Reply with quote
optomeb



Joined: 19 May 2006
Posts: 113
Yes the refferal number is the userid of that username
  Reply with quote
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.
  Reply with quote
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
  Reply with quote
plantino



Joined: 13 May 2006
Posts: 96
All doable.
  Reply with quote
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
:)
  Reply with quote
Page 1 of 1
Post new topic   Reply to topic    Web Design Forums -> HTML forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group