Help with a little script

Status
Not open for further replies.

Serge

Solid State Member
Messages
8
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 "
\n";
}
mysql_free_result($result);
?>

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

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

Could someone please tell me what I'm doing wrong.
 
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);
?>

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!
 
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);
?>
 
Status
Not open for further replies.
Back
Top Bottom