SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help changing to a dynamic dropdown list.

    At the moment I have a blank field where users must enter a correct ID number of a person in order to populate several fields for this person on a new page.

    I need to change this free field in to a dropdown list. I already have the dropdown list. When one is selected I want data to automatically populate several fields on a form in a new page as it is currently happening now by typing in the correct ID number.

    This is the code that is

    Code:
    	if ($_SERVER["REQUEST_METHOD"] == "POST") {
    		if ((string)intval($_POST["playerid"]) != $_POST["playerid"]) $playerIDNotValid = 1;
    		$sql = "select playerid from player where playerid = ".(int)$_POST["playerid"];
    		$rsPlayer = $db->query($sql);
    		if (mysql_num_rows($rsPlayer)) {
    			header("Location: /assessment-create.php?playerid=".intval($_POST["playerid"]));
    			die();
    		} else {
    			$playerIDNotValid = 1;
    		}
    		
    		if ($playerIDNotValid) {
    			include("top.php");
    			echo('<p>Player ID not valid.</p><p><a href="/assessor.php">Back</a></p>');
    			include("rightcol-ecomm.php");
    			include("bottom.php");
    		}
    	}
    This is the code to enter a players ID.

    Code:
    <form name="form1" method="post">
    										
    							<label for="playerid">Existing Player:</label>
    							 
    							<input type="text" id="playerid" name="playerid" maxlength="18" size="18" />
    											
    							<input type="submit" name="submit2" value="Submit" />
    										
    			</form>
    This is the code to select the correct players.

    Code:
    <?
    	$sql = "select
    				assessment.*,
    				player.firstname,
    				player.surname
    			from
    				assessment,
    				player
    			where
    				assessment.assessorid = ".$_SESSION["assessorid"]." and 
    				assessment.playerid = player.playerid
    			order by
    				player.firstname";
    	$rsAssessment = $db->query($sql);
    	if (mysql_num_rows($rsAssessment)) {
    ?>
    Now how can I make a dropdown list from the selected players and update a form at assessment-create.php

    Any help would be greatly appreciated as I'm new at this.

    Thanks in advance

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Let me see if I've understood it correctly. You already have a list of users in the first list (the one that has replaced the old text field), and what you want to do is to submit the form when a user is selected from the list? Or do you want to populate the first list dynamically with users stored in a database?
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    this is what I need.

    Thanks for the quick response.

    Yes I already have a list of users that I need to populate my dropdown list.

    I want to replace the the old text field with my dropdown list and submit the form when a user is selected from the list.

    Thanks in advance

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is it something like this that you're looking for?

    PHP Code:
    <form name="form1" method="post">
    <select name="playerid" onchange="this.form.submit()">
    <?php

    $sql 
    'SELECT id, name FROM users';
    $result $db->query($sql);

    while(
    $row mysql_fetch_assoc($result))
      echo 
    "<option value=\"{$row['id']}\">{$row['name']}</option>\n";

    ?>
    </select>
    <input type="submit" name="submit2" value="Submit" />
    </form>
    I've left the submit button intact so that users without Javascript can submit the form too.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great.

    Now I think this is the code that selects the correct players.
    Code:
    <?
    	class PlayerList {
    		var $db;
    		
    		function PlayerList(&$db) {
    			$this->db = &$db;
    		}
    		
    		function getPlayerList($assessorid) {
    			$arrayPlayer = array();
    			
    			$sql = "select
    						distinct assessment.playerid
    					from
    						assessment
    					where
    						assessment.assessorid = ".$assessorid;
    			$rsPlayer = $this->db->query($sql);
    			if (mysql_num_rows($rsPlayer)) {
    				while ($rowPlayer = mysql_fetch_array($rsPlayer)) {
    					$arrayPlayer[] = $rowPlayer["playerid"];
    				}
    				
    				$sql = "select
    							player.playerid,
    							player.firstname,
    							player.surname
    						from
    							player
    						where
    							player.playerid in (".implode(",", $arrayPlayer).")
    						order by firstname";
    				
    				$arrayPlayer = array();
    				$arrayPlayer[] = 0;
    				
    				$rsPlayer = $this->db->query($sql);
    				if (mysql_num_rows($rsPlayer)) {
    					while ($rowPlayer = mysql_fetch_array($rsPlayer)) {
    						$arrayPlayer[] = array("playerid" => $rowPlayer["playerid"], "name" => $rowPlayer["firstname"].' '.$rowPlayer["surname"]);
    					}
    					return($arrayPlayer);
    				} else {
    					return(false);
    				}
    			} else {
    				return(false);
    			}
    		}
    	}
    ?>
    This code is in an include file. So how can I get this to populate my dropdown?

  6. #6
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code I think I need?

    Code:
    <?
    	} if ($_SESSION["assessor"]) {
    		require_once("playerlist.inc.php");
    		$myPlayerList = &new PlayerList($db);
    		$_SESSION["arrayPlayerChart"] = $myPlayerList->getPlayerList($_SESSION["assessorid"]);
    		if (sizeof($_SESSION["arrayPlayerChart"]) > 1) {
    ?>
    How do I attach this to the dropdown?

  7. #7
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm not sure, but perhaps something like this?

    PHP Code:
    <form name="form1" method="post">
    <select name="playerid" onchange="this.form.submit()">
    <?php

    include 'playerlist.php'// change to your filename
    $assessor_id 0// change to the correct value

    $playerlist = &new PlayerList($db);
    $players $playerlist->getPlayerList($assessor_id);

    foreach( 
    $players as $player )
    {
      echo 
    "<option value=\"{$player['playerid']}\">"
        
    ."{$player['name']}</option>\n";
    }

    ?>
    </select>
    <input type="submit" name="submit2" value="Submit" />
    </form>
    Edit:

    Didn't see your post until now.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  8. #8
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?
    	session_start();
    	if (!$_SESSION["assessor"]) {
    		header("Location: /login.php");
    		die();
    	}
    	
    	include_once("config.inc.php");
    	include_once("db.inc.php");
    	
    	if ($_SERVER["REQUEST_METHOD"] == "POST") {
    		if ((string)intval($_POST["playerid"]) != $_POST["playerid"]) $playerIDNotValid = 1;
    		$sql = "select playerid from player where playerid = ".(int)$_POST["playerid"];
    		$rsPlayer = $db->query($sql);
    		if (mysql_num_rows($rsPlayer)) {
    			header("Location: /assessment-create.php?playerid=".intval($_POST["playerid"]));
    			die();
    		} else {
    			$playerIDNotValid = 1;
    		}
    		
    		if ($playerIDNotValid) {
    			include("top.php");
    			echo('<p>Player ID not valid.</p><p><a href="/assessor.php">Back</a></p>');
    			include("rightcol-ecomm.php");
    			include("bottom.php");
    		}
    	}
    	include("top.php");
    ?>
    
    
    
    <?
    	$sql = "select
    				assessor.*
    			from
    				assessor
    			where
    				assessorid = ".$_SESSION["assessorid"];
    	$rsAssessor = $db->query($sql);
    	if (mysql_num_rows($rsAssessor)) {
    		$rowAssessor = mysql_fetch_array($rsAssessor);
    		echo('<p style="float:right;"><a href="/assessor-create.php?edit=1">Edit Profile</a></p>');
    		echo('<h1>'.$rowAssessor["firstname"].' '.$rowAssessor["surname"].' - Assessor Home</h1>');
    		echo('<div id="credits"><h3>Purchase Credits & Assessment Kit</h3><p>You have <strong>'.$rowAssessor["credits"].' </strong> credits in your account.</p>');
    		echo('<p><a href="gotostore.php">Purchase more credits</a></p>');
    		echo('<p><a href="../ecomm/index.php">Purchase Assessment Kit</a></p>');
    		echo('<p><em>Oncourt Assessment reserves the right to revoke complimentary credits</em></p></div>');
    	}
    ?>
    
    			<h2>Existing Player</h2>
    						<p>Select your Player's name from the list.</p>
    								
    						<form name="form1" method="post">
    <select name="playerid" onchange="this.form.submit()">
    <?php
    
    include '../inc/playerlist.inc.php'; // change to your filename
    $assessor_id = 0; // change to the correct value
    
    $playerlist = &new PlayerList($db);
    $players = $playerlist->getPlayerList($assessor_id);
    
    foreach( $players as $player )
    {
      echo "<option value=\"{$player['playerid']}\">"
        ."{$player['name']}</option>\n";
    }
    
    ?>
    </select>
    <input type="submit" name="submit2" value="Submit" />
    </form>  </td>
    					<td width="47%" valign="top">
    
    			<h2><strong>New Player</strong></h2>
    						<p><a href="/assessor-playercreate.php">Enter results for a new Player</a>. Select this link to enter On Court Assessment results for a player's first Official ITN On Court Assessment. </p></td>
    				</tr>
    			</table>
    			
    		</td>
    	</tr>
    		
    		
    
    	
    </table>
    <p align="center"><img src="images/450rule.gif" /></p>
    <h2>Past Assessments</h2>
    		
    <table width="98%">
    	<tr> 
    		<td width="50%" valign="top">
    			<h3>Existing Assessments</h3>
    
    
    <?
    	$sql = "select
    				assessment.*,
    				player.firstname,
    				player.surname
    			from
    				assessment,
    				player
    			where
    				assessment.assessorid = ".$_SESSION["assessorid"]." and 
    				assessment.playerid = player.playerid
    			order by
    				player.firstname";
    	$rsAssessment = $db->query($sql);
    	if (mysql_num_rows($rsAssessment)) {
    ?>
    <form name="form1" action="assessor-print.php" method="post">
    	<p>
    <?
    		while ($rowAssessment = mysql_fetch_array($rsAssessment)) {
    ?>
    		<input type="checkbox" name="printAssessment[]" value="<? echo($rowAssessment["assessmentid"]); ?>"> <a href="/assessment-thankyou.php?assessmentid=<? echo($rowAssessment["assessmentid"]); ?>"><? echo($rowAssessment["date"]); ?></a> <? echo(htmlentities($rowAssessment["firstname"])); ?> <? echo(htmlentities($rowAssessment["surname"])); ?> <? echo(($rowAssessment["printed"]) ? "(printed)" : "(not printed)"); ?><br />
    <?
    		}
    ?>
    	</p>
    	
    	<p>
    		<input type="submit" name="submit" value="Print Selected" />
    	</p>
    </form>
    <?
    	}
    ?>
    
    
    		</td>	
    
    		<td valign="top">
    <?
    	    if ($_SESSION["assessor"]) {
    		require_once("playerlist.inc.php");
    		$myPlayerList = &new PlayerList($db);
    		$_SESSION["arrayPlayerChart"] = $myPlayerList->getPlayerList($_SESSION["assessorid"]);
    		if (sizeof($_SESSION["arrayPlayerChart"]) > 1) {
    ?>
    		
    		<h3>Rejected Assessments</h3>
    <?
    	$sql = "select
    				assessment.*,
    				player.firstname,
    				player.surname
    			from
    				assessment,
    				player
    			where
    				assessment.assessorid = ".$_SESSION["assessorid"]." and 
    				assessment.playerid = player.playerid and
    				assessment.approved = 2
    			order by
    				assessment.date";
    	$rsAssessment = $db->query($sql);
    	if (mysql_num_rows($rsAssessment)) {
    ?>
    		<p><strong>Note:  The following assessments have been rejected.</strong></p>
    
    			<p>
    <?
    		while ($rowAssessment = mysql_fetch_array($rsAssessment)) {
    ?>
    		<a href="/assessor-editassessment.php?assessmentid=<? echo($rowAssessment["assessmentid"]); ?>"><? echo($rowAssessment["date"]); ?></a> <? echo(htmlentities($rowAssessment["firstname"])); ?> <? echo(htmlentities($rowAssessment["surname"])); ?><br />
    <?
    		}
    ?>
    			</p>
    		</td>
    <?
    	}
    ?>
    
    	</tr>
    </table>
    
    <?
    	include("rightcol-ecomm.php");
    	include("bottom.php");
    ?>
    This is now producing the following error.

    Parse error: parse error, unexpected $ in /home/o/oncou/www/assessor4.php on line 218

    Line 218 is the last line.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •