Results 1 to 2 of 2

Thread: PHP code building help for more than one DB

  1. #1
    Join Date
    Jul 2010

    PHP code building help for more than one DB

    Okay, so I'm building some player profiles and I need help with php to set it up. On the SQL form, I already asked for help and received what I needed. Originally, I figured I could set the PHP code by myself but the answer I got in the forum at the link below is going to need some more complex PHP code that is out of my league.


    What I want to do is have a game-by-game on each player's profile.

    So, I'm going to query only the player's ID (player.php?ID=1). From that, I want to pull the profile information (already done).

    I'm also going to pull up game-by-game stats.

    What I want the completed output to have is

    Date | Opponent | Stat1 | Stat2 ...

    So what I need to be able to do is the pick out all stat entries (in the stat table) for player ID (1), then the date and opponent for each game in which said player played in from the Game and Opponent tables. Be sure to look at the link above to get the exact table setup.

    Thanks everyone for your help...let me know if you need more information.

  2. #2
    Join Date
    Jul 2010
    that's what the season stats table was for. It's a "stage table": something that's relatively new to me.
    The idea is you can use it for formatting the data from other tables before you query the "big chunk" of data that you're looking to get. Stage tables serve many other purposes.
    ALTER TABLE season_stats ADD(game_date date(), opponent varchar(#));
    UPDATE season_stats SS,stats S,games G,opponent O,player P SET
    SS.date = G.max(game_date)
    SS.player_ID = $_GET['ID'] //validate first
    SS.opponent <> O.team
    SS.stat1 <> S.stat1
    SS.stat2 <> S.stat2
    SS.stat3 <> S.stat3
    SS.stat4 <> S.stat4
    "ALL (the-KEYs) <MATCH>"
    >>LIKE THIS>>
        P.player_ID=$_GET['ID'] // validate first
    AND G.game_ID=S.game_ID
    AND O.opponent_ID=G.opponent_ID
    If you actually built those tables using innoDB, myISAM, and MEMORY I have no idea what kind of results you'll get. InnoDB can be a diva when it comes to deleting records, so be careful or switch to myISAM for everything (will make update queries slower).

    A few big queries and some smart sql tables can save you from writing insane php interfaces and classes.

    You could write a 100 different queries to get the exact output you're looking for. The table structure was supposed to make it obvious how to select a certain set of data using foreign keys. The php code it probably just one class and one interface.

    interface block_profile {
        const top  = "<table blah blah blah"
        const top_end = "</table>"
        const stat1 = <tr blach blah
    class profile inmplements block_profile {
           public function __construct() {
                $this->ID = self::validate_ID();
                $this->last_game_stats = self::get_last_stats();
           public function output():
                echo self::top;
                echo this->$stat1
                echo self:: blah blah blah; //you probably want to write table rules with #ID rules to format these
                echo self::top_end;
           static private function validate_ID() {
                query = select unique ids
                fetch query array
                if !$_GET[id] in_array(the array u just made) die('invalid ID');
                return $_GET['ID']; 
           static function get last stats()
               query that big query i spoke about before
               return the array it produces;
    $page = new Profile();
    Also, from what I understand is you only have 1 DB which has multiple tables. If you're using multiple DB's for multiple teams, I recommend you either change the tables to incorporate it or write a table with a FEDERATED engine.
    Last edited by eval(BadCode); 08-12-2010 at 09:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center