PDA

View Full Version : [PHP] Fetch - Error?



loserWILL
02-01-2008, 05:36 PM
I have the following code, and it keeps giving me this error:


Parse error: syntax error, unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/stay/public_html/loser/admin/viewall.php on line 214Line 214 is:

<div id=\"news_top\"><div align=\"left\"><div id=\"title\">$title - <a href=\"edit.php?id=<?php echo(\"\" . $fetch[\"id\"] . \"\");?>\">edit</a></div></div></div>+rep to all suggestions.


<?php
// Database
include "config.php";

// Lets check the mySQL
$sql = "SELECT * FROM news";
$check = mysql_query("SELECT id, title, name, date, post FROM news") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");

//Now, define the content variable(s)
while ($display = mysql_fetch_array($check)) {
$title = $display['title'];
$name = $display['name'];
$date = $display['date'];
$post = $display['post'];

//Lets display it!
echo "<div id=\"news_wrap\">
<div id=\"news_top\"><div align=\"left\"><div id=\"title\">$title - <a href=\"edit.php?id=<?php echo(\"\" . $fetch[\"id\"] . \"\");?>\">edit</a></div></div></div>
<div id=\"news_middle\"><div id=\"text2\">$post</div>
<div id=\"etc\">Posted by: <strong>$name</strong> on <strong>$date</strong>.</div></div>
<div id=\"news_bottom\"></div>
</div>";
}
?>

Moved by Agesilaus (Forum Moderator) from Designing & Development: Please post in the correct forum next time. :)

Chippiewill
02-01-2008, 05:38 PM
Can you have '< , >' outside an echo in the middle of a php string?

loserWILL
02-01-2008, 05:41 PM
Okay, thanks.

[Oli]
02-01-2008, 05:42 PM
<div id=\"news_top\"><div align=\"left\"><div id=\"title\">$title - <a href=\"edit.php?id=<?php echo("\" . $fetch[\"id\"] . \"\");?>\">edit</a></div></div></div>

looking at your backslashes I asume the <div id=news etc is in an echo ?

ifso just do:



echo("

<div id=\"news_top\"><div align=\"left\"><div id=\"title\">$title - <a href=\"edit.php?id=" . $fetch[id] . "\">edit</a></div></div></div>

");

no need to backslash EVERY "

Hitman
02-01-2008, 05:43 PM
Try this should work.


<?php
// Database
include "config.php";

// Lets check the mySQL
$sql = "SELECT * FROM news";
$check = mysql_query("SELECT id, title, name, date, post FROM news") or die("Onoes! Something is wrong! Please contact loserWILL for assistance (this is an error).");

//Now, define the content variable(s)
while ($display = mysql_fetch_array($check)) {
$title = $display['title'];
$name = $display['name'];
$date = $display['date'];
$post = $display['post'];

//Lets display it!
echo "<div id=\"news_wrap\">
<div id=\"news_top\"><div align=\"left\"><div id=\"title\">$title - <a href=\"edit.php?id=".$fetch['id']."\">edit</a></div></div></div>
<div id=\"news_middle\"><div id=\"text2\">$post</div>
<div id=\"etc\">Posted by: <strong>$name</strong> on <strong>$date</strong>.</div></div>
<div id=\"news_bottom\"></div>
</div>";
}
?>

Want to hide these adverts? Register an account for free!