-3
<?php 
    $pvp=mysql_query("SELECT * FROM characters ORDER BY level DESC");
echo "<table><tr><th>Character</th><th>Level</th><th>Tribe</th></tr>";
while ($row = mysql_fetch_array($pvp)) {
    echo "<tr><td>".($row['charname'])."</td><td>".($row['level'])."</td><td>".($row['tribe'])."</td><td><form action='/scripts/pvp.php' method='post'><input type='submit' name='pvp' value='Battle!'></form></td></tr>";
}
echo "</table>";
?>

In this script, I loop through an array and display all data stored in a variable ($pvp). I would like to add an input button at the end of each row that allows me to post that specific row to another page to use in another script. How would I do this?

2
  • LMGTFY stackoverflow.com/questions/1217824/… Commented Jun 25, 2013 at 18:29
  • You could populate form inputs with PHP just like you are populating your table: <input type="text" name="charname" value="<?=$row['charname']?>" /> Commented Jun 25, 2013 at 18:31

1 Answer 1

0

Inside while() loop:

echo "<tr><td>".($row['charname'])."</td>";
echo "<td>".($row['level'])."</td><td>".($row['tribe'])."</td>";
echo "<td><form action='/scripts/pvp.php' method='post'>";
echo "<input type=hidden name='tribe' value='".$row['tribe']."'>";
echo "<input type=hidden name='charname' value='".$row['charname']."'>";
echo "<input type=hidden name='level' value='".$row['level']."'><input type='submit' name='pvp' value='Battle!'></form></td></tr>";
Sign up to request clarification or add additional context in comments.

3 Comments

Adding the hidden inputs into my loop breaks my current page.
Previously, my script - sans form - would display a table that had 3 rows of information, plus the headers. When I add that to the script, the page displays blank.
Oh, yeah, forgot to remove extra "(". Try now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.