Jump to content

[SOLVED] Help with PHP table from MySQL query


majormajor71

Recommended Posts

Hi all,

 

A newbie php/mysql user here hoping to find a little bit of help from all you good fellows. I have a simple html table that returns the team names created by a user.

 

$result = mysql_query("SELECT * FROM Team WHERE Cpt_ID='".$captain_id."'")

  or die(mysql_error());

echo "<table border='1'>";

echo "<tr> <th></th> <th></th> <th>Team Name </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="player_add.php">Add Players</a>';

echo "</td><td>";

echo '<a href="player_remove.php">Remove Players</a>';

echo "</td><td>";

        echo $row['team_name'];

        echo "</td></tr>";

 

echo "</table>";

I would like then to be able to allow the user to add or delete players from the teams that he/she created. My problem is that I am unsure how to specify which team was selected to be modified. I understand how to pass variables through pages with sessions, but I do not know how the "player_add" or "player_remove" page will know which team was selected. I would be most grateful for any help at all. Thanks so much, and let me know if anything is unclear.

 

Paul

Link to comment
Share on other sites

As rlindauer said you pass the value from the link 

<?php
echo '<a href="player_add.php?team=Add">Add Players</a>';
echo '<a href="player_add.php?team=Remove">Remove Players</a>';
?>

And in player_add.php you keep get those value and do stuff what you want...

<?php
if (isset($_GET['team']) && $_GET['team']=="Add")
{
$you_want_to_add = $_GET['team'];
echo "I selected $you_want_to_add";
}
elseif (isset($_GET['team']) && $_GET['team']=="Remove")
{
$you_want_to_add = $_GET['team'];
echo "I selected $you_want_to_add";
}
else 
{
echo "Nobody clicked on the link, that's why we are here ";
}

?> 

 

Hope you get the idea...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.