Correct Syntax?

I’m having trouble getting my code to echo the right thing from my database.

The function sends in two numbers ($id and $pNum). I have checked those numbers and the values in my database.

[php]function randomEventPrize($id,$pNum){
$pT = $pNum."_te"; //either 1_te, 2_te, or 3_te
$pP = $pNum."_re"; //either 1_re, 2_re, or 3_re
$re = mysql_fetch_assoc(mysql_query(“SELECT ‘$pT’,’$pP’ FROM randomE WHERE id=’$id’”));
echo $re[$pT];
echo $re[$pP];
}[/php]

The echo statements echo the $pT and $pP values and not what’s in the database. What’s the correct syntax to do this?

Please check database connection first. If it’s fine than you are forget to define database name.
See below code

[php]

$con = mysql_connect(“localhost”,“root”,“root”); //your databse connection detail (“localhost”, “db_username”,”db_password”)
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
//must define database name here
//you can replace test with your database name
// I think your missing this line. If not than see comment define in function
mysql_select_db(“test”, $con);
function randomEventPrize($id,$pNum){
$pT = $pNum."_te"; //either 1_te, 2_te, or 3_te
$pP = $pNum."_re"; //either 1_re, 2_re, or 3_re
// remove single quotes used around $pT, $pP
$re = mysql_fetch_assoc(mysql_query(“SELECT $pT,$pP FROM rendom WHERE id=$id”));
echo $re[$pT];
echo $re[$pP];
}
randomEventPrize(1,1);

[/php]

i hope you get your solution. provide your feedback

Sanjay

My database is defined, but it ended up being the quotes! It’s always the little things XD

Thank you!

Sponsor our Newsletter | Privacy Policy | Terms of Service