/    Sign up×
Community /Pin to ProfileBookmark

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.

[url]http://www.webdeveloper.com/forum/showthread.php?t=234083[/url]

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Aug 13.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.
[CODE]
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
...
...
...
WHERE
"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

[/CODE]


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.

[CODE]
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();
$page->output();

[/CODE]


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.
×

Success!

Help @phpkyle92 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...