chrisidas Posted June 17, 2011 Share Posted June 17, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/239622-is-it-possible-to-add-a-remove-button-to-mysql-select-results/ Share on other sites More sharing options...
revraz Posted June 17, 2011 Share Posted June 17, 2011 Of course, why not? Since each row returns can have a ID, you just update that ID. Quote Link to comment https://forums.phpfreaks.com/topic/239622-is-it-possible-to-add-a-remove-button-to-mysql-select-results/#findComment-1230950 Share on other sites More sharing options...
chrisidas Posted June 17, 2011 Author Share Posted June 17, 2011 How would i go about doing that? Still pretty new to this lol Any good examples you know of or anything? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/239622-is-it-possible-to-add-a-remove-button-to-mysql-select-results/#findComment-1230951 Share on other sites More sharing options...
dragon_sa Posted June 17, 2011 Share Posted June 17, 2011 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/239622-is-it-possible-to-add-a-remove-button-to-mysql-select-results/#findComment-1230961 Share on other sites More sharing options...
chrisidas Posted June 17, 2011 Author Share Posted June 17, 2011 Will give that a go, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/239622-is-it-possible-to-add-a-remove-button-to-mysql-select-results/#findComment-1231059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.