Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP arrays in use with Form Drop down menus
Old 11-13-2005, 05:19 AM PHP arrays in use with Form Drop down menus
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Can anyone help me out with this one? I'm currently trying to add a management section to a website for a friend. Neither of us coded it, so I don't really get how this guy who DID code it has done it.
I have never really used drop downs, arrays and PHP together, so I kinda don't know what i'm doing, except I could copy his code.. But then it's wrong!

All I need to do, is make a new drop down, but with management only, just for the admin. No one else. Here's the code he has for the page:
PHP Code:
<?php

require('inc/Predefined.php');
require(
'inc/Mysql.php');
require(
'inc/User.php');
require(
'parts/m_start.php');
require(
'parts/m_menu.html');





// remove memmbership
if ($_POST['user_id'] && $_POST['activity'])
{
    if (
$_POST['activity'] === 'active')
    {
        
$sql "UPDATE s_teams SET
                active=0
                WHERE user_id="
intval($_POST['user_id']);
        
$sdb->get_query($sql);

    }
    elseif (
$_POST['activity'] === 'inactive')
    {
        
$sql "UPDATE s_teams SET
                active=1
                WHERE user_id="
intval($_POST['user_id']);
        
$sdb->get_query($sql);

    }
}


if (
$_POST['user_id'] && isset($_POST['rankID']) && $_POST['gameID'])
{
    
$sql "UPDATE s_teams SET
            rankID="
. (intval($_POST['rankID']) ? intval($_POST['rankID']) : 'NULL') ."
            WHERE user_id="
intval($_POST['user_id']) ."
            AND gameID="
intval($_POST['gameID']);
    
$sdb->get_query($sql);
}

?>
<div id="inner_header">Roster: <?php echo $row['name'?></div>
<div class="tab_cell">
<table class="stats" cellpadding="0" cellspacing="0">
<thead>
<tr>
    <td width="250">Name</td>
    <td>Status</td>
    <td>Rank</td>
    <td>Profile</td>
</tr>
</thead>
<tbody>

    <?php


$sql 
"SELECT gameID,name FROM s_games
        ORDER BY name"
;
$resOut $sdb->get_query($sql);

while (
$rowOut mysql_fetch_assoc($resOut))
{
    echo 
'<tr><td colspan="4" align="center">- '$rowOut['name'] ." -</td></tr>\n\n";

    
// finn all users
    
$sql "SELECT st.user_id, st.active, st.rankID, fu.username FROM
            s_teams st INNER JOIN forum_users fu USING(user_id)
            WHERE st.gameID=
{$rowOut['gameID']}
            ORDER BY fu.username"
;

    
$res $sdb->get_query($sql);

    
$sql "SELECT * FROM s_ranks
            WHERE gameID="
intval($rowOut['gameID']) ."
            ORDER BY name"
;
    
$res2 $sdb->get_query($sql);
    
$ranks = array(=> 'no rank');
    while (
$row mysql_fetch_assoc($res2))
    {
        
$ranks[intval($row['rankID'])] = $row['name'];
    }



    while (
$row mysql_fetch_assoc($res))
    {
    
?>
    <tr class="tr1" onmouseover="this.className='tr2'" onmouseout="this.className='tr1'">

    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post" style="display:inline">
    <td>
    <?php echo $row['username'?>
     </td>
     <input type="hidden" name="user_id" value="<?php echo $row['user_id'?>">
     <td>
     <input type="submit" class="black_box" name="activity" value="<?php echo ($row['active'] ? 'active' 'inactive'?>">
     </td>
    </form>


    <td>
    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post" style="display:inline" name="ranks<?php echo $rowOut['gameID'].$row['user_id'?>">
     <input type="hidden" name="user_id" value="<?php echo $row['user_id'?>">
         <input type="hidden" name="gameID" value="<?php echo $rowOut['gameID'?>">
         <select name="rankID" onChange="document.forms['ranks<?php echo $rowOut['gameID'].$row['user_id'?>'].submit()">
         <?php
         
foreach (array_keys($ranks) as $key)
         {
            
?><option value="<?php echo $key ?><?php if ($row['rankID'] == $key) echo 'selected' ?>><?php echo $ranks[$key?></option><?php
         
}
         
?>
         </select>
    </form>
    </td>
    <td>
    <form action="m_user_profile.php" method="post">
    <input type="hidden" name="user_id" value="<?php echo $row['user_id'?>">
    <input type="submit" class="black_box" value="Profile">
    </form>
    </td>
    </tr>
    

    
    
    
    <?php
    
}
}
    
?>
    
    <!-- start hack -->
    <tr>
<td colspan="4" align="center">
    
- Management -
    <tr class="tr1" onmouseover="this.className='tr2'" onmouseout="this.className='tr1'">

        <br /><br />
        This section is very hard. Still in development. Too much school work at the moment! :'(
        <br /><br />
    </td>
    </tr>
    </tr>
<!-- end hack -->
    
    
    </tbody>
    </table>
</div>


<?php


require('parts/end.php');

?>
Thanks in advance guys.
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-13-2005, 08:33 AM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
This will display all the entries in an array we set ($test) in a drop down menu. Not sure if this is exactly what you wanted. Let me know if you need any more help on this.

PHP Code:
<body>
<form action="xxxx" method="get">
    <select name="Test" onchange="this.form.submit();">
    <optgroup Label="Test">    
    <?php
    $test 
= array("Option 1""Option 2""Option 3");
    
    foreach (
$test as $value) {
        print (
"<option value=\"$value\">$value</option>\n");
    }
    
?>
    </optgroup>
    </select>
    <input type="submit" class="button" value="Submit" />
</form>
</body>
Nahele is offline
Reply With Quote
View Public Profile
 
Old 11-13-2005, 06:08 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
PHP Code:
 <select name="rankID" onChange="document.forms['ranks<?php echo $rowOut['gameID'].$row['user_id'?>'].submit()">
         <?php
         
foreach (array_keys($ranks) as $key)
         {
            
?><option value="<?php echo $key ?><?php if ($row['rankID'] == $key) echo 'selected' ?>><?php echo $ranks[$key?></option><?php
         
}
         
?>
         </select>
This part creates the select, you just need an extra section on the end to add your new option:

PHP Code:
 <select name="rankID" onChange="document.forms['ranks<?php echo $rowOut['gameID'].$row['user_id'?>'].submit()">
         <?php
         
foreach (array_keys($ranks) as $key)
         {
            
?><option value="<?php echo $key ?><?php if ($row['rankID'] == $key) echo 'selected' ?>><?php echo $ranks[$key?></option><?php
         
}
        
if(
$username == "whoever is the admin" ) {
  echo 
'<option value="manager">Manager</option>';
}

 
?>
         </select>
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to PHP arrays in use with Form Drop down menus
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.23883 seconds with 12 queries