[Help with a little script] -



Help with a little script

Discuss Help with a little script



Posted by: Serge

Ok I have written a script and I need some help with it the script is:

[PHP]
<?php
include ("sql.php");

$result = mysql_query("SELECT articleid, title FROM article") or
die (mysql_error());

while ($row = mysql_fetch_array($result))
{
echo "<a href=\"http://www.surrix.net/db/read.php?id=$row["articleid"]\">$row["title"]</a>";
echo "<br>\n";
}
mysql_free_result($result);
?>
[/PHP]

I'm a complete noob at this but when I run the script I get this error:

[QUOTE]
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/surrix/public_html/db/latest.php on line 9
[/QUOTE]

Could someone please tell me what I'm doing wrong.



Posted by: Myth Pharoah

[PHP]<?php
include ("sql.php");

$result = mysql_query("SELECT articleid, title FROM article") or
die (mysql_error());

while ($row = mysql_fetch_array($result))
{
echo "<a href=\"http://www.surrix.net/db/read.php?id=" . $row["articleid"] . "\">$row["title"]</a>";
echo "\n";
}
mysql_free_result($result);
?>[/PHP]

That should fix it. You were using a " inside a ". That doesn't work. If you want to use arrays directly without coming out of echo use have to remove the quotes in them
So instead of
$array["key"] or $array['key'] <-- To use this technique you have to come come out of echo.
$array[key] <-- Just directly put 'em in. :)

Hope that helps!



Posted by: Serge

would I have to do the same thing to $row[title]?



Posted by: Myth Pharoah

Aye!
[PHP]
<?php
include ("sql.php");

$result = mysql_query("SELECT articleid, title FROM article") or
die (mysql_error());

while ($row = mysql_fetch_array($result))
{
echo "<a href=\"http://www.surrix.net/db/read.php?id=" . $row["articleid"] . "\">" . $row["title"] . "</a>";
echo "\n";
}
mysql_free_result($result);
?>
[/PHP]