John
John

Reputation:

Adding a hyperlink to a PHP-generated table

In the code below, I am trying to print out a 1-column, 25-row table, with each row being a hyperlink to "booksearch.php?find=urlencode('TABLE_NAME')&searching=yes&search=search".

The hyperlink part is not working. For the line below with the hyperlink, I get this error message: "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'".

Any ideas on how I can change the line below with the hyperlink in order to make it work?

echo "<table class=\"samples\">";
$index = mysql_query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='bookfeather' order by CREATE_TIME desc limit 25");
while ($row = mysql_fetch_array($index))
{
  echo "<tr><td>".'<a href="booksearch.php?find=urlencode('TABLE_NAME')&searching=yes&search=search">'.$row['TABLE_NAME'].'</a>'."</td></tr>";
}
echo "</table>";

Upvotes: 0

Views: 564

Answers (2)

EvilChookie
EvilChookie

Reputation: 573

Your echo is wrong:

echo "<tr><td>".'<a href="booksearch.php?find=urlencode('TABLE_NAME')&searching=yes&search=search">'.$row['TABLE_NAME'].'</a>'."</td></tr>";

Should be:

echo "<tr><td><a href=\"booksearch.php?find=" . urlencode($row['TABLE_NAME']) . "&searching=yes&search=search\">" . $row['TABLE_NAME'] . "</a></td></tr>";

That should do the trick.

Upvotes: 1

Andrew Moore
Andrew Moore

Reputation: 95334

Try the following:

 echo '<tr><td><a href="booksearch.php?find='.urlencode($row['TABLE_NAME']).'&searching=yes&search=search">'.$row['TABLE_NAME'].'</a></td></tr>';

You had urlencode() inside the string, which single-quotes (') which closed your string and caused problems. urlencode() is a function and needs to be used outside the string.

You were also missing the $row variable reference in your urlencode() call.

Upvotes: 2

Related Questions