Jump to content

Multiple drop menu's from table in one form


giraffemedia

Recommended Posts

Hi guys

 

i've got a page on my website for a sports scorecard to be entered. This consists of a form with 11 rows (one for each player) each consisting of player_name, runs_scored and runs_total entries. I have a seperate table in my db called player_profiles and i'm using this to pull in a list/menu of player names in the player_name entry. I have this working fine for one name, however i'm trying to get 11 rows performing the same SELECT query and the only way I can get it to work is having multiple (11) SELECT queries and multiple (11) while loops to populate the lists. is there any other way of doing this, or am I doing the right thing?

 

If I have 1 SELECT query and use more than 1 list/menu, the first one works fine, but all other return with blank values - I presume because i've already pulled the data from the db.

 

Anyone have any idea?

 

Regards

 

James

Okay Revraz, thanks for your help.

 

Here is the code I have so far...

 

<?php
//Start session
session_start();
//Check whether the session variable
//SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {
	header("location: ./library/access_denied.php");
	exit();
}

require_once ('includes/config.php');
require_once ('includes/opendb.php');


$query = "SELECT player_profile_first_name, player_profile_last_name FROM player_profiles ORDER BY player_profile_last_name";
	$result=mysql_query($query);
if (!$result)	{ 
	die('Invalid query: ' . mysql_error());
}
$num=mysql_num_rows($result); //Set the number of rows returned from the query as a variable

$query2 = "SELECT player_profile_first_name, player_profile_last_name FROM player_profiles ORDER BY player_profile_last_name";
	$result2=mysql_query($query2);
if (!$result2)	{ 
	die('Invalid query: ' . mysql_error());
}
$num2=mysql_num_rows($result2); //Set the number of rows returned from the query as a variable



?>


<html>
<head>
<title>. : Kilve Cricket Club - Admin : .</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../kilvecc.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript" type="text/javascript" src="date_picker/datetimepicker.js"></script>
</head>

<body>

<div id="wrapper">
	<div id="header"></div>
	<div id="main_nav">
		<?php include ('admin_nav.php'); ?>
	</div>


	<div id="main_content">
		<div id="main_content_inner">
			<form name="fixture_result" method="post" action="../library/add_fixture_result_exec.php">
			<table width="500" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Date: </p></td>
				<td align="left" valign="top">
				  <input name="match_date" type="text" id="match_date"> <a href="javascript:NewCal('match_date','yyyymmdd')"><img src="date_picker/cal.gif" width="16" height="16" border="0" alt="Pick a date" /></a>

				</td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Time: </p></td>
				<td align="left" valign="top"><input name="match_time" type="text" id="match_time" value="<? echo ($_POST['match_time']); ?>">
				</td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Opponent: </p></td>
				<td align="left" valign="top"><input name="match_team" type="text" id="match_team"></td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Venue: </p></td>
				<td align="left" valign="top"><input name="match_venue" type="text" id="match_venue"></td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Result: </p></td>
				<td align="left" valign="top"><input name="match_date2" type="text" id="match_date2"></td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Comments: </p></td>
				<td align="left" valign="top"><textarea name="match_comments" id="match_comments"></textarea></td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p>Match Scorecard: </p></td>
				<td align="left" valign="top"><textarea name="match_scorecard" id="match_scorecard"></textarea></td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p> </p></td>
				<td align="left" valign="top"> </td>
			  </tr>
			  <tr>
				<td width="150" align="right" valign="top"><p> </p></td>
				<td align="left" valign="top"><input type="submit" name="Submit" value="Submit">
			    <input type="reset" name="Submit2" value="Reset"></td>
			  </tr>
			</table>

		</form>	
            
           <? if ($num > 0) {echo "<select name=\"select\" id=\"player_list\">\n";
while($row = mysql_fetch_array($result)){
?>
<option  value="<?php echo $row['player_profile_first_name'].' '.$row['player_profile_last_name']; ?>"><?php echo $row['player_profile_first_name'].' '.$row['player_profile_last_name'];
?></option>
<?php
}
?>
</select>
            
            <? while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
		echo '<p>'.$row['player_profile_first_name'].' '.$row['player_profile_last_name'].'</p>';
		} 

		mysql_free_result ($result);}

		else { echo 'There are none you twat';

		} ?>
            <br />
            
                        
               <? if ($num2 > 0) {echo "<select name=\"select\" id=\"player_list\">\n";
while($row2 = mysql_fetch_array($result2)){
?>
<option  value="<?php echo $row2['player_profile_first_name'].' '.$row2['player_profile_last_name']; ?>"><?php echo $row2['player_profile_first_name'].' '.$row2['player_profile_last_name'];
?></option>
<?php
}
?>
</select>
            
            <? while ($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)) {
		echo '<p>'.$row2['player_profile_first_name'].' '.$row2['player_profile_last_name'].'</p>';
		} 

		mysql_free_result ($result);}

		else { echo 'There are none you twat';

		} ?>
            
            
            
            
            
            
		</div>
	</div>

<div id="main_content_right">
		<div id="main_content_right_inner">
		<?php include ('latest_news.php'); ?>
		</div>

	</div>


	<div id="footer"></div>		


</div>

</body>
</html>

 

James

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.