Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with quoting?

Status
Not open for further replies.

hansu

Programmer
Mar 12, 2002
89
I am trying to insert a variable $row[link] that is stored in a MySQL-Database into a webpage. So far I have not been able to quote the string correctly at href=\" ...
I keep receiving the error: ...unexpected T_VARIABLE in ...

$result = mysql_query("select link, textde from links order by link");
while ( $row = mysql_fetch_array($result) ){
print(&quot;<tr valign=\&quot;top\&quot;><td><a href=\&quot; . &quot;$row[&quot;link&quot;]&quot; . \&quot;>&quot; . $row[&quot;link&quot;] . &quot;</a></td><td class=\&quot;text\&quot;>&quot; . ereg_replace(&quot;(\n|\r)+&quot;,&quot;<br>&quot;,$row[&quot;textde&quot;]) . &quot;</td></tr>&quot;);
}


Thanks for your assistance.
Hansu
 
use:
print(&quot;<tr valign=\&quot;top\&quot;><td><a href=\&quot;.&quot;$row['link']&quot;.

or better:
print(&quot;<tr valign=\&quot;top\&quot;><td><a href=\&quot;.&quot;${row['link']}&quot;.

PM
 
Hi predamarcel

Your second proposal works fine. (With {...})
The first one doesn't.


Thanks for your help.
Hansu
 
PHP does not like associative array references inside quoted strings. In any regard, it's not necessary to put bare variables inside quotes anyway.

Try:

$result = mysql_query(&quot;select link, textde from links order by link&quot;);
while ( $row = mysql_fetch_array($result) )
{
print '<tr valign=&quot;top&quot;><td><a href=&quot;' . $row['link'] . '&quot;>' . $row['link'] . '</a></td><td class=&quot;text&quot;>' . ereg_replace('(\n|\r)+','<br>',$row['textde']) . '</td></tr>';
}

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top