List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:December 6 2004 10:06pm
Subject:RE: Database values to variables
View as plain text  
[snip]
I need to convert database values into php variables.
Let me explain:

i.e. 

select firstbase, secondbase, thirdbase, home from
allstars where firstbase = 122;

Now I want to use all those field names as variables
with the same record information they would have if
you just ran the above statement.

i.e 
$fb =  $firstbase
$sb = $secondbase
$tb = $thirdbase
[/snip]

Here is the code -->

<?php

$sql = "select firstbase, secondbase, thirdbase, home from allstars
where firstbase = '122'" ;
if(!($returnedData = mysql_query($sql, $yourDatabaseConnection))){
	echo mysql_error() . "\n";
	exit();
}

while($row = mysql_fetch_array($returnedData)){
	/* here are your variables */
	$fb = $row['firstbase'];
	$sb = $row['secondbase'];
	$tb = $row['thirdbase'];
	/* ...and so on ...*/
}
echo $fb . "<br>\n"; //print out to the screen
echo $sb . "<br>\n"; //print out to the screen
echo $tb . "<br>\n"; //print out to the screen

?>

My suggestion is that you work some basic PHP/MySQL tutorials and use
the PHP general list (php-general@stripped) for questions like
this. Make sure you have RTFM, STFA, and STFW before posting, those guys
can be merciless.

Thread
Database values to variablesStuart Felenstein6 Dec
RE: Database values to variablesJay Blanchard6 Dec
  • RE: Database values to variablesStuart Felenstein6 Dec