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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 09-25-2009, 10:00 PM   #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?
Copephobia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 09-25-2009, 10:49 PM   #2 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 719
OS: Linux Mint 7

My System

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:
Rank - Username - Alliance - etc.
01 - Copephobia - 1 - etc.
02 - Bob - 2 - etc.
...or is this what you WANT to display?

(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 |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-25-2009, 10:50 PM   #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.
I want it to display:

Code:
Rank - Username - Alliance - etc.
01 - Copephobia - Tag1 - etc.
02 - Bob - Tag2 - etc.
Copephobia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-25-2009, 10:57 PM   #4 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 719
OS: Linux Mint 7

My System

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 |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-25-2009, 11:30 PM   #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.
Copephobia is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-26-2009, 03:59 AM   #6 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 719
OS: Linux Mint 7

My System

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 |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 07:36 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85