0
$resultSystem = mysql_query("SELECT * FROM templates where templateId = 1");
while($row = mysql_fetch_assoc($resultSystem))
{
$Part1 = $row["Part1"];
}

$name = "Peter";
echo $Part1;

In my database $Part1 results in $name. I would like the code to print the name "Peter", however it prints $name. How do I make PHP print the value of the variable?

2 Answers 2

2

if $Part1 = 'name';

$name ="Peter";

Then

echo $$Part1 will print "Peter"
Sign up to request clarification or add additional context in comments.

2 Comments

I prefer for clarity ${$Part1}
woah, I've never thought this kind of thing was possible :o... yep... over 6 years of programming, and I didn't know this small trick... -.-
0

Use function eval() like

eval("echo $Part1");

However, be very careful so the users don't launch malicious code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.