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

You can just pass a value to player_add.php so that player_add.php knows which team was selected.

 

<?php
echo '<a href="player_add.php?team='.$row['team_id'].'">Add Players</a>';
?>

 

You know, substitute the '.$row['team_id'].' for the actual id or value you want to pass.

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

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.