Jump to content

Recommended Posts

Hi Guys,

 

I have two tables

 

players table:

 

q1.jpg

 

And an appearances table:

 

  q1a.jpg

 

Now each of the rows in the appearances table holds the player_id of the player that played in that shirt for a specific match.

 

Now here’s my question.  In my CMS I have written a function to get the players name into a dropdown box, but place the value (player_id) into the apperances table:

 

The Function

// Start function to pull out data for all
function db_result_to_array($result) 
{ 
   $res_array = array(); 

   for ($count=0; $row = mysql_fetch_array($result); $count++) 
     $res_array[$count] = $row; 

   return $res_array; 
}

// Get the player names out of database where team_id = $team_id for match reports
function get_player_names() { 
    $query='SELECT player_id, player_name FROM players'; 
    $result=mysql_query($query); 
    if(FALSE==$result) 
        return FALSE;
    if((0 || FALSE)==mysql_num_rows($result)) { 
        return false; 
    } else { 
        $result=db_result_to_array($result); 
        return $result; 
    } 
}

 

The Dropdown for player_one

 

<select class="input" name="player_one" size="1"  style="width: 145" tabindex="1">
  <option value="" selected>player_one</option>
    <?php 
            $type_array=get_player_names(); 
            foreach ($type_array as $players) 
           { 
              print("<option value=\"".$players['player_id']."\">".$players['player_name']."</option>\n"); 
          } 
     ?>
</select>

 

Now this works great for INSERTING, but my problem is when I want to edit and UPDATE the data in the appearances table.  Say I went to the URL:

 

www.mywebsitedomainnamehereyes.com/index.php?appearances_id=2

 

I’d want to get the dropdown to look in the appearances table for the 2nd record and force the dropdown in this case to show the value Steve Daly and then edit it if needs be.

 

Can anyone help me on this, as i'm not sure how to go about doing it.

 

Thanks

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/56166-function-keeping-values/
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.