Jump to content
Larry Ullman's Book Forums

Recommended Posts

This statement works fine as it is

 

echo '<p>'.$query_row['name'].'</p>';

 

But how would it be possible to turn '<p>'.$query_row['name'].'</p>' into a variable that could be called back by a print or echo statement ?

 

A not working example

 

$myvar = '<p>'.$query_row['name'].'</p>';

 

echo $myvar;

 

Does anyone know how this is possible?

Link to comment
Share on other sites

Ashley, after the page loads, go to the view source option in your browser.

As Stephen suggested, likely, the value of $query_row['name'] is an empty string, but the p tags should still be in the markup (even though you don't see anything on the screen).

Link to comment
Share on other sites

I think I am getting a little further, the p tags do display in the mark up. If i type $myvar = '<p>\'.$query_row[\'name\'].\'</p>';

 

echo($myvar) prints the code out as '.$query_row['name'].' (I was getting nothing before)  and the markup displays as <p>'.$query_row['name'].'</p> when echo '<p>'.$query_row['name'].'</p>' is used the mark up correctly displays <p>Ashley</p>

 

any further ideas ?

Link to comment
Share on other sites

'<p>\'.$query_row[\'name\'].\'</p>' outputs the markup <p>'.$query_row['name'].'</p> and you see '.$query_row['name'].' on the screen because you are escaping some of the single quotes with backslashes, thus making them be interpreted as literals quotes.

 

If you're echoing '<p>'.$query_row['name'].'</p>' and seeing <p>Ashley</p> in your markup, then you should definitely see Ashley on the screen. Are you not seeing that? If so, then you are likely hiding the displaying of that element using CSS or something because by default, <p>Ashley</p> will always output Ashley to the screen.

 

Please let us know.

Thanks.

Link to comment
Share on other sites

Sorry I did not answer your question HartleySan, I have checked and the CSS is not hiding anything. After checking with a friend I was told I had totally misused single (') and double (") quotation marks in the script which was creating further errors that the text editor did not pick up and I had set the variable outside of the function where it should have been inside of the function therefore the function was unable to access the variable

 

Thank you helping me HartleySan and StephenM

Link to comment
Share on other sites

 Share

×
×
  • Create New...