Jump to content

[Resolved] trying to set options for certain users


Seitan

Recommended Posts

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?
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

try 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]
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]
<?php
echo "<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]
<?php
echo "<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 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.