PDA

View Full Version : Any PHP gurus here?



PartisanEntity
December 6th, 2009, 07:14 PM
I noticed we have some fellow web developers here. I am quite a newbie at PHP, and trying to write a search script. I want to generate a link from a mysql_query result.

This is what I have so far but I get errors:


while($rowOne = mysql_fetch_array($content))
{
echo '<a href="searchmultiple.php?SearchTerm='.$rowOne['term'].'&FromLanguage='.$FromLanguage.'&SearchID='$rowOne['id'].'">'.$rowOne['term'].'</a>';
}

Here is the error I get:


Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /Applications/MAMP/htdocs/eilv/search.php on line 36

Any idea what could be causing this? I can't see it.

:)

Sam
December 6th, 2009, 07:31 PM
A dot is missing (in bold red below)...


while($rowOne = mysql_fetch_array($content))
{
echo '<a href="searchmultiple.php?SearchTerm='.$rowOne['term'].'&FromLanguage='.$FromLanguage.'&SearchID='.$rowOne['id'].'">'.$rowOne['term'].'</a>';
}


You can also put variables in the string to avoid too much concatenations. You may gain in clarity.

while($rowOne = mysql_fetch_array($content))
{
echo "<a href=\"searchmultiple.php?SearchTerm={$rowOne['term']}&FromLanguage={$FromLanguage}&SearchID={$rowOne['id']}\">{$rowOne['term']}</a>";
}

Bachstelze
December 6th, 2009, 07:32 PM
You're missing a period before $rowOne['id'].

Also what Sam said.

NoaHall
December 6th, 2009, 07:39 PM
I concur with the above statements.

When you get a error like the above, usually the best way to find the cause is to ask someone else to check. If you keep staring at it, you won't see it.

Mmmbopdowedop
December 6th, 2009, 07:42 PM
<?
while($rowOne = mysql_fetch_array($content))
{
?>
<a href="searchmultiple.php?SearchTerm=<?php echo $rowOne['term']; ?>&FromLanguage=<?php echo $FromLanguage; ?>&SearchID=<? echo $rowOne['id']; ?>"><?php echo $rowOne['term']; ?></a>
<?
}
?>

I find it easier to close php for that section, keeps all the highlighting there, more readable. :)

Bachstelze
December 6th, 2009, 08:13 PM
Also good practice says to replace & with &amp;.

PartisanEntity
December 7th, 2009, 11:31 AM
Thanks everyone for all the great feedback and tips.

I stared at it for about 2 hours and could not see that the dot was missing :) *facepalm*