The14thGOD Posted June 29, 2007 Share Posted June 29, 2007 I keep getting this error but i can't figure out why, I believe it is this code: <?php while($row = mysql_fetch_array($results)) { $row['image'] = str_replace("../","",$row['image']); $row['body'] = str_replace("\r\n","<br /><br />",$row['body']); $row['body'] = str_replace("\n","<br /><br />",$row['body']); echo("<h3>$row['headline']</h3>"); echo("<img src=\"$row['image']\" width=\"334\" height=\"184\" />"); echo("<p>$row['body']</p><br />"); } ?> when i take it out it doesn't do it anymore help asap please thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 Try wrapping the variables in brackets ({}). I don't know what else it would be. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 while($row = mysql_fetch_array($results)) { $row['image'] = str_replace("../","",$row['image']); $row['body'] = str_replace("\r\n","<br /><br />",$row['body']); $row['body'] = str_replace("\n","<br /><br />",$row['body']); echo"<h3>".$row['headline']."</h3>"; echo"<img src=\"".$row['image']."\" width=\"334\" height=\"184\" />"; echo"<p>".$row['body']."</p><br />"; } that will work Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted June 29, 2007 Author Share Posted June 29, 2007 yep,the second method worked, though im confused because I have never had to do that before and it works on my site....if possible would you mind explaining what exactly that does? thank you for the help Quote Link to comment Share on other sites More sharing options...
btherl Posted June 29, 2007 Share Posted June 29, 2007 The problem is when you use array elements (like $row['image']) inside a double-quoted string. You need to "protect" them from misinterpretation like this: print "The image is $row['image']"; # WRONG, will give error print "The image is {$row['image']}\n"; # RIGHT, no error teng84's method also works (he is using "." to stick strings together with variables). Quote Link to comment Share on other sites More sharing options...
The14thGOD Posted June 29, 2007 Author Share Posted June 29, 2007 ah alright, I think I understand now. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.