iJoseph Posted January 11, 2010 Share Posted January 11, 2010 I have some code that makes a news article but I need it in a variable to add it to a template. I have the following: <?php $content = " $db = mysql_connect(\"localhost\", \"user\", \"pass\"); mysql_select_db(\"inerdso1_ribz\",$db); $result = mysql_query(\"SELECT * FROM news ORDER BY id DESC LIMIT 3\"); while ($row = mysql_fetch_array($result)) { echo ' <table border=\"0\" width=\"50%\" id=\"table1\"> <tr> <td width=\"196\"></td> <td>Title: ' . $row['title'] . '</td> </tr> <tr> <td width=\"196\" valign=\"top\">Author: ' . $row['author'] . '</td> <td valign=\"top\">' . $row['message'] . '</td> </tr> </table> '; } "; ?> But I keep getting the following error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/inerdso1/public_html/ribz/news.php on line 11 I don't know what toi do and would like it if you could help me. Joseph Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/ Share on other sites More sharing options...
RaythMistwalker Posted January 11, 2010 Share Posted January 11, 2010 Your not setting the array anywhere on that page. Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/#findComment-993010 Share on other sites More sharing options...
iJoseph Posted January 11, 2010 Author Share Posted January 11, 2010 It works perfecty when I don't put it in the variable. Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/#findComment-993023 Share on other sites More sharing options...
Maq Posted January 11, 2010 Share Posted January 11, 2010 What in the world are you doing? Put the results in a variable, not the PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/#findComment-993059 Share on other sites More sharing options...
iJoseph Posted January 11, 2010 Author Share Posted January 11, 2010 Ah, Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/#findComment-993064 Share on other sites More sharing options...
Maq Posted January 11, 2010 Share Posted January 11, 2010 You also may want to check out the heredoc syntax, in your particular case. Quote Link to comment https://forums.phpfreaks.com/topic/188091-mysql-connection-in-variable-help/#findComment-993069 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.