![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 3
OS: XP
|
MySQL Multiple queries
I am currently coding a multiplayer game in php and I am lost on one part.
On the rankings page, I have the table display the following: Rank - Username - Alliance - etc. 01 - Copephobia - 1 - etc. 02 - Bob - 2 - etc. What I want to do is write the alliance tag for each alliance the member is in. Here's how it goes: -Sort player id's based on rank -Display player information Here's what I want to do next: -print alliance tag based on alliance id how exactly what I do that? |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) | |
|
Design Team Member
|
Re: MySQL Multiple queries
I'm a little on the confused side so instead of listing a BUNCH of possible scenarios I'm reading and asking you which one you're experiencing (which is confusing for both of us), let me just ask one question at a time...
Is the scoreboard you show (below) already built? Quote:
(ps: a breakdown of your table structure would be beneficial...)
__________________
Free Resources PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |Web Design/Programming - KompoZer (Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting | |
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 3
OS: XP
|
Re: MySQL Multiple queries
It displays:
Code:
Rank - Username - Alliance - etc. 01 - Copephobia - 1 - etc. 02 - Bob - 2 - etc. Code:
Rank - Username - Alliance - etc. 01 - Copephobia - Tag1 - etc. 02 - Bob - Tag2 - etc. |
|
|
|
|
|
#4 (permalink) |
|
Design Team Member
|
Re: MySQL Multiple queries
Is "Tag1" an alliance name?
__________________
Free Resources PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |Web Design/Programming - KompoZer (Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting | |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Dec 2008
Posts: 3
OS: XP
|
Re: MySQL Multiple queries
The alliance tag, yes.
Edit: Here's the code that is currently used to outpt the table: Code:
$sql = "SELECT id FROM ranking WHERE rank > 0";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$num_rows = ceil($num_rows / 50);
if($_GET['page'] < 1) { $_GET['page'] = 1; }
if($_GET['page'] > $num_rows) { $_GET['page'] = $num_rows; }
settype($_GET['page'], "int");
$arr_id = array();
$arr_name = array();
$arr_gold = array();
$arr_sett = array();
$arr_pop = array();
$add_sql = "";
$start_rank = 50 * ($_GET['page'] - 1);
$sql = "SELECT id, rank FROM ranking
WHERE rank>0
ORDER BY rank
LIMIT 50 OFFSET $start_rank";
$result = mysql_query($sql);
while ($ranking = mysql_fetch_assoc($result)) {
$arr_id[$ranking[id]] = $ranking[rank];
$add_sql .= " || id=" . $ranking[id];
}
$arr_min = min($arr_id);
$arr_id = array_flip($arr_id);
mysql_free_result($result);
$add_sql = substr($add_sql, 4);
$sql = "SELECT stats.id, stats_gold, stats_population, stats_alliance FROM stats
WHERE $add_sql";
$result = mysql_query($sql);
while ($stats = mysql_fetch_assoc($result)) {
$arr_gold[$stats[id]] = $stats[stats_gold];
$arr_pop[$stats[id]] = $stats[stats_population];
$sql = "SELECT members, tag FROM alliance WHERE allid = $stats[stats_alliance]";
$result2 = mysql_query($sql);
$alliance = mysql_fetch_assoc($result2);
mysql_free_result($result2);
if($alliance[members] > 9) {
$arr_all[$stats[id]] = $alliance[tag];
}
}
$sql = "SELECT user, id FROM user
WHERE $add_sql";
$result = mysql_query($sql);
while ($user = mysql_fetch_assoc($result)) {
$arr_name[$user[id]] = $user[user];
}
echo "<table border='0' cellpadding='5' cellspacing='0'>\n<tr><td width='50'><b>Rank</b></td><td width='150'><b>Username</b></td><td width='120'><b>Alliance</b></td><td width='120'><b>Population</b></td><td><b>Gold</b></td></tr>";
for($i = $arr_min; $i < $arr_min + 50; $i++) {
$pos = $arr_id[$i];
if(isset($arr_name[$pos])) {
echo "<tr><td>" . number_format($i, 0, '.', ',') . "</td>";
echo "<td><a href='stats.php?id=" . $pos . "'>" . $arr_name[$pos] . "</a></td>";
echo "<td><i>" . $arr_all[$pos] . "</i></td>";
echo "<td>" . number_format($arr_pop[$pos], 0, '.', ',') . "</td>";
echo "<td>" . number_format($arr_gold[$pos], 0, '.', ',') . "</td></tr>\n";
}
}
echo "</table>";
}
Last edited by Copephobia; 09-25-2009 at 11:32 PM. |
|
|
|
|
|
#6 (permalink) |
|
Design Team Member
|
Re: MySQL Multiple queries
I need to see how your database is set up. It LOOKS like there's no alliance ID in the user table otherwise you'd probably be pulling that. If that's the case, your database isn't fully normalized and that makes it difficult to do JOINs.
__________________
Free Resources PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |Web Design/Programming - KompoZer (Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting | |
|
|
|
![]() |
| Thread Tools | |
|
|