| We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
- Pages:
- 1
- 2
| Tricky PHP/SQL problem | |
|---|---|
| Tweet Topic Started: May 5 2005, 07:03 PM (801 Views) | |
| JCink | May 5 2005, 07:03 PM Post #1 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Stumped on this one. Not sure if theres a way out or a way to do it. :/ Okay, here is my problem. http://jcinkcom.ho8.com/quickarcade/q/Arca...on=leaderboards Okay. Heres how it works. That's a leaderboard. Every time someone is "champion" of a game on that thing, their number on the leaderboard goes up. If the "champion" gets taken away from them, it goes down. This information is drawn from several places. That entire row of names is drawn by querying the table PhpQuickArcade_account_data ORDER BY username ASC Now the winnings are stored in a seperate table. PhpQuickArcade_user_champs. So, to get those numbers there of champs, I use something like this: $heh = $scores["username"]; $champtable = mysql_query("SELECT * FROM PhpQuickArcade_user_champs WHERE username = '$heh'"); Okay. Then I can count that, and then stick the count var in the leaderboard HTML and it counts nicely. My main problem is: How am I going to get this to put the user with the most "wins" or "champs" at the top? I just can't see any way else I can do it since I have things setup the way I do. Is there a way? Thanks for any help on this... |
![]() |
|
| Seth | May 5 2005, 07:16 PM Post #2 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
My eyes >_< Randomly titled variables, huge table names, selecting *, ack. Use a JOIN.
I made an assumption that you have a username field in both tables. I don't know your db structure though. |
![]() |
|
| JCink | May 5 2005, 07:31 PM Post #3 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Hmm, okay... shield your eyes >_< and also I just realized that this code here isn't working right anyway:
With that setup, how do I use that? I don't understand. Thanks. And, I know the mysql_num_rows isn't right... I forgot about Select count, but I'll fix that. I've never used a JOIN once before. |
![]() |
|
| Seth | May 5 2005, 07:33 PM Post #4 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Ow ow ow ow ow ow. I'll take 3 hours and get back to you
|
![]() |
|
| Seth | May 5 2005, 07:38 PM Post #5 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Basic idea:
|
![]() |
|
| JCink | May 5 2005, 07:56 PM Post #6 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Okay. Thanks for the code. But, I have nothing to order by. Which is the main problem. I'll try to describe it better.
This is the user champs table. How it works is, there can only be one good score in there by somebody. Example from here: INSERT INTO `PhpQuickArcade_user_champs` VALUES (15, 'Sean', 2388, 'MonsterHatch'); From that, all I do is count the number of times WHERE username = '$var'; ... the var is the username var it comes from logging into their account to display the total wins. No actual number is being stored, I'm just counting the number of rows a certain username comes up. How this even works out is, if the top score of a game is beaten, it opens that table, deletes, removes their name, and updates the score. It knows what game and what to delete because flash sends out the "IDNAME" which is what I call it... So basically I have nothing to ORDER BY which is the problem. Either that or I just dont understand the code you gave me. |
![]() |
|
| Seth | May 5 2005, 08:00 PM Post #7 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
You're ORDER'ing by c, which is a count of how many times their username appears in that table. |
![]() |
|
| JCink | May 5 2005, 08:19 PM Post #8 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
It doesn't seem to work for me. I thought I should set "c" to something? I'm sorry, I was taught wrong how to count the number of rows in a table, so this is confusing me a bit. Thanks, -jcink |
![]() |
|
| Seth | May 5 2005, 11:25 PM Post #9 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Could you dump your databases and e-mail them to me? seth@invisionfree.com I'll make sure it works with your dbs
|
![]() |
|
| JCink | May 6 2005, 12:30 PM Post #10 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Really? :blink: Thanks a bunch. Okay then I sent it over. heres a copy here, since GMail doesn't always work right:
|
![]() |
|
| Seth | May 6 2005, 12:53 PM Post #11 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Got it. Will do tonight. |
![]() |
|
| JCink | May 6 2005, 11:11 PM Post #12 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Thanks. I'm going to try to learn a bit about that code though that you gave already right now. If I come up with something; I'll post here... Thanks again. |
![]() |
|
| Seth | May 6 2005, 11:15 PM Post #13 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Ok
|
![]() |
|
| Seth | May 7 2005, 09:22 PM Post #14 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Got it!
|
![]() |
|
| JCink | May 7 2005, 09:39 PM Post #15 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Thanks that worked perfectly. I just inserted it over my old query and it worked. PHEW! Thanks! Okay... one last thing... let me see if I got this right as to what you did :
First you select the username, and then count the number of times it appears? That's what this piece does?
I guess; that; you defined defined the count thing AS dracula? That's what AS does? and of course you get the info FROM PhpQuickArcade_account_data... I think.
This I looked up on w3schools earlier ![]() and the rest I get... I just want to make sure I know the two top parts and what they do and Thanks again! |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Technology Chat · Next Topic » |
- Pages:
- 1
- 2
| Track Topic · E-mail Topic |
8:35 AM Jul 11
|



![]](../../../../0/1/0/p601690/pipright.png)




8:35 AM Jul 11