displaying a variable in an echo statement
Moderator: General Moderators
displaying a variable in an echo statement
I have written the following code:
function addfaccert($fid, $flname) {
$cert_array = @mysql_query('SELECT * FROM certs ORDER BY CERTS');
if (!$cert_array) {
die('<h2>Error retrieving certs from table!</h2><br>' .
'Error: ' . mysql_error());
}
echo ('
<p align="center">Add Certification for $flname<p>
<table align="center" border="0" width="70%" cellspacing="6">
');
I have tried every combination of "$flname", \"$flname\", '$flname', ''$flname'', etc to get the variable $flname to display its value but all I get is the printing of the actual variable, i.e. the webpage will display "$flname", or \"$flname\", etc. How do I get the value to print to the browser? (I've left off the rest of the function for space consideration since it doesn't deal with the question)
Thanks.
function addfaccert($fid, $flname) {
$cert_array = @mysql_query('SELECT * FROM certs ORDER BY CERTS');
if (!$cert_array) {
die('<h2>Error retrieving certs from table!</h2><br>' .
'Error: ' . mysql_error());
}
echo ('
<p align="center">Add Certification for $flname<p>
<table align="center" border="0" width="70%" cellspacing="6">
');
I have tried every combination of "$flname", \"$flname\", '$flname', ''$flname'', etc to get the variable $flname to display its value but all I get is the printing of the actual variable, i.e. the webpage will display "$flname", or \"$flname\", etc. How do I get the value to print to the browser? (I've left off the rest of the function for space consideration since it doesn't deal with the question)
Thanks.
-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
Re: displaying a variable in an echo statement
chriso wrote:echo ('
<p align="center">Add Certification for $flname<p>
<table align="center" border="0" width="70%" cellspacing="6">
');
Code: Select all
echo ("<p align='center'>Add certification for ".$flname."<p>
<table align='center' border='0' width='70%' cellspacing='6'>");Re: displaying a variable in an echo statement
Last example, but using "" around the html-values (html good):Sinnix wrote:Code: Select all
echo ("<p align='center'>Add certification for ".$flname."<p> <table align='center' border='0' width='70%' cellspacing='6'>");
Code: Select all
echo ('<p align="center">Add certification for '.$flname.'<p>
<table align="center" border="0" width="70%" cellspacing="6">');- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Just as a note, the actual problem here was that PHP does not parse strings within single quotes so:
will produce
whereas
will produce
Mac
Code: Select all
$info = 'foobar';
echo 'blah $info blah';Code: Select all
blah $info blahCode: Select all
$info = 'foobar';
echo 'blah '.$info.' blah'; // my preferred method
// or
echo "blah $info blah"; // note the double quotesCode: Select all
blah foobar blah