FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Question on Querying..





fizzo
Code:
<?php



$dbserver = 'localhost';

$dbname = 'WWWWWWWWW';

$dbuser = 'WWWWWWWWW';

$dbpasswd = 'WWWWWWW';



$db = mysql_connect($dbserver, $dbuser, $dbpasswd) or die('Could not connect to DB server!');

mysql_select_db($dbname) or die("Could not connect to database: " . mysql_error());



$PLAYER = $_GET['PLAYERID'];

$rplayer = mysql_query("SELECT * FROM Players WHERE PLAYERID = '$PLAYER'") or die(mysql_error());



while($row = mysql_fetch_array($rplayer))



{



$teamid = $row['TEAMID'];

$teamname = $row['TEAM'];

$name = $row['FIRSTNAME'];

$lname = $row['LASTNAME'];

$position = $row['POSITION'];

$age = $row['AGE'];

$college = $row['COLLEGE'];

$experience = $row['EXPERIENCE'];

$height = $row['DISPLAYHEI'];

$weight = $row['WEIGHT'];

$agency = $row['AGENCY'];

$level = $row['LEVEL'];

$happiness = $row['ATTITUDE'];

$consistency = $row['CONSISTENC'];

$greed = $row['GREED'];

$loyalty = $row['LOYALTY'];

$playforwinner = $row['PLAYFORWIN'];

$playtime = $row['PLAYINGTIM'];

$motivation = $row['MOTIVATION'];

$personality = $row['PERSONALIT'];

$durability = $row['DURABILITY'];

$workethic = $row['WORKETHIC'];

$popularity = $row['POPULARITY'];

$fgj = $row['FGJ'];

$ft = $row['FT'];

$fgd = $row['FGD'];

$fgthree = $row['FG3'];

$scoring = $row['SCORING'];

$passing = $row['PASSING'];

$handling = $row['HANDLING'];

$oreb = $row['OREB'];

$dreb = $row['DREB'];

$defense = $row['DEFENDER'];

$discipline = $row['DISCIPLINE'];

$drawfoul = $row['DRAWFOUL'];

$iq = $row['BBALLIQ'];

$steal = $row['STEAL'];

$block = $row['BLOCK'];

$contracta = $row['CY1'];

$contractb = $row['CY2'];

$contractc = $row['CY3'];

$contractd = $row['CY4'];

$contracte = $row['CY5'];

$contractf = $row['CY6'];

$bird = $row['BIRDYEARS'];

$endurance = $row['ENDURANCE'];

};





//Team Photo

$rteam = mysql_query("SELECT * FROM teamlogos WHERE TEAMID = '$teamid'") or die(mysql_error());

while($row = mysql_fetch_array($rteam))

{

$abbr = $row['ABBR'];

$color = $row['COLOR'];



};



//Player Names

$namel = strtolower($name);

$lnamel = strtolower($lname);

$photo = $namel ._. $lnamel;



//Currency Convert

$currencya = number_format($contracta,0);

$currencyb = number_format($contractb,0);

$currencyc = number_format($contractc,0);

$currencyd = number_format($contractd,0);

$currencye = number_format($contracte,0);

$currencyf = number_format($contractf,0);









if(file_exists("WWWW.html"))



{

$template = file_get_contents("WWWW.html");

$template = str_replace("{teamname}", $teamname, $template);

$template = str_replace("{name}", $name, $template);

$template = str_replace("{lname}", $lname, $template);

$template = str_replace("{position}", $position, $template);

$template = str_replace("{age}", $age, $template);

$template = str_replace("{college}", $college, $template);

$template = str_replace("{experience}", $experience, $template);

$template = str_replace("{height}", $height, $template);

$template = str_replace("{weight}", $weight, $template);

$template = str_replace("{happiness}", $happiness, $template);

$template = str_replace("{consistency}", $consistency, $template);

$template = str_replace("{greed}", $greed, $template);

$template = str_replace("{loyalty}", $loyalty, $template);

$template = str_replace("{playforwinner}", $playforwinner, $template);

$template = str_replace("{playtime}", $playtime, $template);

$template = str_replace("{personality}", $personality, $template);

$template = str_replace("{durability}", $durability, $template);

$template = str_replace("{workethic}", $workethic, $template);

$template = str_replace("{popularity}", $popularity, $template);

$template = str_replace("{motivation}", $motivation, $template);

$template = str_replace("{fgj}", $fgj, $template);

$template = str_replace("{fgthree}", ${fgthree}, $template);

$template = str_replace("{ft}", $ft, $template);

$template = str_replace("{fgd}", $fgd, $template);

$template = str_replace("{scoring}", $scoring, $template);

$template = str_replace("{passing}", $passing, $template);

$template = str_replace("{handling}", $handling, $template);

$template = str_replace("{oreb}", $oreb, $template);

$template = str_replace("{dreb}", $dreb, $template);

$template = str_replace("{defense}", $defense, $template);

$template = str_replace("{discipline}", $discipline, $template);

$template = str_replace("{drawfoul}", $drawfoul, $template);

$template = str_replace("{iq}", $iq, $template);

$template = str_replace("{steal}", $steal, $template);

$template = str_replace("{block}", $block, $template);

$template = str_replace("{contracta}", $currencya, $template);

$template = str_replace("{contractb}", $currencyb, $template);

$template = str_replace("{contractc}", $currencyc, $template);

$template = str_replace("{contractd}", $currencyd, $template);

$template = str_replace("{contracte}", $currencye, $template);

$template = str_replace("{contractf}", $currencyf, $template);

$template = str_replace("{bird}", $bird, $template);

$template = str_replace("{endurance}", $endurance, $template);





$template = str_replace("{ppg}", $ppg, $template);



$template = str_replace("{abbr}", $abbr, $template);

$template = str_replace("{color}", $color, $template);

$template = str_replace("{photo}", $photo, $template);

echo $template;

};





?>



How can I insert Database Fields from this part of the code below .. if the Fields are from the other Tables not from Table Players

Because I need to get the Stats data from the other Table and show it on the pages I used another page for the Template or the Skinning.. Thats why the codes above is the declaration and query of of the Database..


Code:
{



$teamid = $row['TEAMID'];

$teamname = $row['TEAM'];

$name = $row['FIRSTNAME'];

$lname = $row['LASTNAME'];

$position = $row['POSITION'];

$age = $row['AGE'];

$college = $row['COLLEGE'];

$experience = $row['EXPERIENCE'];

$height = $row['DISPLAYHEI'];

$weight = $row['WEIGHT'];

$agency = $row['AGENCY'];

$level = $row['LEVEL'];

$happiness = $row['ATTITUDE'];

$consistency = $row['CONSISTENC'];

$greed = $row['GREED'];

$loyalty = $row['LOYALTY'];

$playforwinner = $row['PLAYFORWIN'];

$playtime = $row['PLAYINGTIM'];

$motivation = $row['MOTIVATION'];

$personality = $row['PERSONALIT'];

$durability = $row['DURABILITY'];

$workethic = $row['WORKETHIC'];

$popularity = $row['POPULARITY'];

$fgj = $row['FGJ'];

$ft = $row['FT'];

$fgd = $row['FGD'];

$fgthree = $row['FG3'];

$scoring = $row['SCORING'];

$passing = $row['PASSING'];

$handling = $row['HANDLING'];

$oreb = $row['OREB'];

$dreb = $row['DREB'];

$defense = $row['DEFENDER'];

$discipline = $row['DISCIPLINE'];

$drawfoul = $row['DRAWFOUL'];

$iq = $row['BBALLIQ'];

$steal = $row['STEAL'];

$block = $row['BLOCK'];

$contracta = $row['CY1'];

$contractb = $row['CY2'];

$contractc = $row['CY3'];

$contractd = $row['CY4'];

$contracte = $row['CY5'];

$contractf = $row['CY6'];

$bird = $row['BIRDYEARS'];

$endurance = $row['ENDURANCE'];

};


Thanks hope to hear it from you soon. Thanks!
fizzo
Another good explanation on what I want to have..

Retrieving data from more than one table..

Example from Table 1 I want to display TEAMNAME , PLAYER NAME , RATING etc... and on Table 2 I want to retrieve or query PLAYER ID , PPG , REBOUNDS , STEALS etc... I need this to be query on one single statement.. Hope you help me thanks!
muggle
First - read the manual Smile

You can take a look at this link 12.2.7. SELECT Syntax; it describes the syntax of the SELECT statement in details, including queries on more than one table.

If some parts need additional explanation don't hesitate to ask.
Aredon
If you want to select
TEAMNAME , PLAYER NAME , RATING... from table1
and PLAYER ID , PPG , REBOUNDS , STEALS... from table2
in a single query, I'd personally use this syntax:
Code:

$pname=mysql_real_escape_string($playername);
$pid=(int)$playerid;
$query="SELECT table1.*, table2.* FROM table1,table2 WHERE table1.playername='$pname' AND table2.playerid=$pid LIMIT 1";


The above accomplishes the same thing as:
Code:

$pname=mysql_real_escape_string($playername);
$query1="SELECT * FROM table1 WHERE playername='$name'";
$pid=(int)$playerid;
$query2="SELECT * FROM table2 WHERE playerid='$pid'";

The major difference is that my joint query syntax requires both the player name and player id to be matched lest no results are selected from either table, even if a match is found in one of the tables, while running the two as separate queries would allow for one query to be successful while the other is not.
Related topics
I Have a question . Is it the server support Chinese?
Question before requesting free hosting
question abt posts/mth
Kinda dumb question regarding DNS
A question
UT2004 U like the game? Do u have any question post here.
Question about DNS!
Question about Domain!
another uni.cc question
Question
Question abt lang. support...
question!!!!!!
A question about Naruto
C++ Question
PHPBB2 Question. (What MOD makes the featured announcements?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.