Forum Moderators: coopster
I want to make a script which will make a nicks (a column of nicks) clickable. When you will click that link it would redirect me to main.php, but it must transver $row['nick'] to main.php by get method (or any other method).
If anyone can help, please reply as fast as possible. I'm little a short on a time.
Thanks for every word!
<?php
$result = mysql_query("SELECT * FROM gameusers") or die(mysql_error());
echo "<table border='0'>";
echo "<tr> <th>Name</th> <th>Gold</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<a href=\"main.php?{$row['nick']}\">{$row['nick']}</a>";
echo "</td><td>";
echo $row['gold'];
echo "</td></tr>";
}
echo "</table>";?>
or you can use dots:
echo "<a href=\"main.php?" . $row['nick'] . "\">".{$row['nick'] . "</a>";
I myself prefer the dot syntax, but both should work.
PS. To put quotes into html escape them with backslash: \"
Hope this helps and have fun with php!
Michal
I would use mcibor's second example but there is a minor syntax error, extra brace ;)
I would also add a param name
echo "<a href=\"main.php?nick=" . $row['nick'] . "\">".$row['nick'] . "</a>";
then you could grab the nick in main.php by accessing
$_GET['nick']