Forum Moderators: coopster

Message Too Old, No Replies

giving action to text

actions are usually for buttons

         

rokec

7:37 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



I'm using this code to write content of the table:
<?php $result = mysql_query("SELECT * FROM gameusers");
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 $row['nick'];
echo "</td><td>";
echo $row['gold'];
echo "</td></tr>";
}
echo "</table>";?>

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!

mcibor

8:44 pm on Sep 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just put a link there:

<?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

mcibor

8:46 pm on Sep 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And welcome to Webmasterworld Rokec!

rokec

9:30 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



And how i detect in "main.php" which nick was clicked?

Thanks for support.

jatar_k

4:59 pm on Sep 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can get it from the url, well actually the $_GET array

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']