Jump to content

Is it possible to add a remove button to mySQL select results?


chrisidas

Recommended Posts

Back again with another newbie question.

 

Is it possible for me to have a submit button next to each result, so that i can change the transfer status for that particualr player to "unavailable"

 

For Example i would like the table to look like:

Name            Status          Remove Button

Player one      sale        button to change status

Player two      loan        button to change status

<?php 
$result = mysql_query("SELECT * FROM players WHERE teamname='Arsenal' and transferstatus='sale' or teamname='Arsenal' and transferstatus='loan' ORDER BY transferstatus");

echo "<table border='1' width='500' bordercolor='black' align='left'>
<tr>
<th width='150' align='center'>Name</th>
<th width='25' align='center'>Position</th>
<th width='25' align='center'>Rating</th>
<th width='25' align='center'>Value</th>
<th width='25' align='center'>Transfer Type</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td width='25' align='centre'>" . $row['playername'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playerposition'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playerrating'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playervalue'] . "</td>";
  echo "<td width='25' align='center'>" . $row['transferstatus'] . "</td>";
  echo "</tr>";
  echo "</tr>";
  echo "</tr>";
  echo "</tr>";
  echo "</tr>";
  }
echo "</table>";

?>  

Any ideas?

there are many ways to do this depending on how you want to use it, the easiest would be to use GET but this can lead to issues depending on who has access to the page that can modify the database

 

here is the GET method assuming the unique id for a player in your table is playerID and the page is called player.php you can use what ever you have set it to in the database

 

<?php 
//check for update request
if (isset($_GET['transfer']) {
  $transfer=$_GET['transfer'];
  mysql_query("UPDATE players SET transferstatus='unavailable' WHERE playerID='$transfer'");
}

$result = mysql_query("SELECT * FROM players WHERE teamname='Arsenal' and transferstatus='sale' or teamname='Arsenal' and transferstatus='loan' ORDER BY transferstatus");

echo "<table border='1' width='500' bordercolor='black' align='left'>
<tr>
<th width='150' align='center'>Name</th>
<th width='25' align='center'>Position</th>
<th width='25' align='center'>Rating</th>
<th width='25' align='center'>Value</th>
<th width='25' align='center'>Transfer Type</th>
<th width='25' align='center'>Remove</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td width='25' align='centre'>" . $row['playername'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playerposition'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playerrating'] . "</td>";
  echo "<td width='25' align='center'>" . $row['playervalue'] . "</td>";
  echo "<td width='25' align='center'>" . $row['transferstatus'] . "</td>";
  echo "<td width='25' align='center'><a href=\"player.php?transfer=". $row['playerID'] . "\">Change Status</a></td>";
  echo "</tr>";
   }
echo "</table>";

?>  

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.