Seitan Posted December 10, 2006 Share Posted December 10, 2006 Hey, I'm trying to set up options for certain users on my site, but I keep getting an error Here is my code[code]echo " <tr> <td align=\"left\"><a href=\"http://{$row['url']}\" target=\"_new\">{$row['title']}</a></td> <td align=\"left\">{$row['description']}</td> if ($_SESSION['user_id'] == '?' || $_SESSION['user_id'] == '?') { <td align=\"center\"><a href=\"edit_url.php?uid={$row['url_id']}\">edit</a></td> } </tr>\n";[/code]and here is my error[quote]Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/29/d178597021/htdocs/php/view_urls.php on line 74[/quote]Line 74 is the if statement, but it looks fine to me (but im a noob so that doesn't mean much). Could someone help? Quote Link to comment Share on other sites More sharing options...
drifter Posted December 10, 2006 Share Posted December 10, 2006 first if you use a single quote you can avoid escaping so many double quotes.second I believe multidemsional variables can not be parse good when in double quotes.third your parse error is because your if is in the quotestry this[code]echo ' <tr> <td align="left"><a href="http://' . $row['url'] . '" target="_new">' . $row['title'] . '</a></td> <td align="left">' .$row['description'] . '</td>'; if ($_SESSION['user_id'] == '?' || $_SESSION['user_id'] == '?') { echo '<td align="center"><a href="edit_url.php?uid=' . $row['url_id']. '">edit</a></td>'; }echo '</tr>\n';[/code] Quote Link to comment Share on other sites More sharing options...
jbehen Posted December 10, 2006 Share Posted December 10, 2006 Not sure, but I will give it a shot....If you are spreading the string to be 'echoed' across multiple lines, I think you have to finish each line with a closing quote and a . to concatenate it to the next line. Also, you can clean up how it appears in the source code with \n and \t (new line and tab, respectively.) Obviously, the variables have been replaced show something will show up. Hopefully, that helps.Idea...[code]<?phpecho "<tr>\n" . "\t<td align=\"left\">\n" . "\t\t<a href=\"http://row_url_variable\" target=\"_new\">row_title_variable</a>\n" . "\t</td>\n" . "\t<td align=\"left\">\n" . "\t\trow_description_variable\n" . "\t</td>\n";if ($_SESSION['user_id'] == '?' || $_SESSION['user_id'] == '?') { echo "\t<td align=\"center\">\n" . "\t<a href=\"edit_url.php?uid=row_url_id\">edit</a>\n" . "\t</td>\n"; }echo "</tr>\n";?>[/code]results in:[code]<tr> <td align="left"> <a href="http://row_url_variable" target="_new">row_title_variable</a> </td> <td align="left"> row_description_variable </td></tr>[/code]Without the tabs for indentation control:[code]<?phpecho "<tr>\n" . "<td align=\"left\">\n" . "<a href=\"http://row_url_variable\" target=\"_new\">row_title_variable</a>\n" . "</td>\n" . "<td align=\"left\">\n" . "row_description_variable\n" . "</td>\n";if ($_SESSION['user_id'] == '?' || $_SESSION['user_id'] == '?') { echo "<td align=\"center\">\n" . "<a href=\"edit_url.php?uid=row_url_id\">edit</a>\n" . "</td>\n"; }echo "</tr>\n";?>[/code]results in this HTML output:[code]<tr><td align="left"><a href="http://row_url_variable" target="_new">row_title_variable</a></td><td align="left">row_description_variable</td></tr>[/code] Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 10, 2006 Author Share Posted December 10, 2006 [quote author=drifter link=topic=118093.msg482253#msg482253 date=1165782597]first if you use a single quote you can avoid escaping so many double quotes.second I believe multidemsional variables can not be parse good when in double quotes.third your parse error is because your if is in the quotes[/quote]Yeah that worked, except I have a \n\n\n\n at the top of the page Quote Link to comment Share on other sites More sharing options...
Seitan Posted December 10, 2006 Author Share Posted December 10, 2006 nevermind, I just took out the \n and that worked fine, thanks for the help 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.