Jump to content

Populate Drop Down: mysql_field_name


CEinNYC

Recommended Posts

Hi all -

 

I'm trying to populate a drop down menu, and the items listed on the drop down menu are three of the field titles (names).  Here's what I am playing with....  "intelligence" "speed" "power" and "reserve" are three field names (and a series of numbers are stored in each field).

How do I incorporate mysql_field_name into the mix?   

 

 

   

  <select name="id" style="">

<?php while($row = mysql_field_name($options)):?>

<option value="<?php echo $row['id']; ?>">

<?php echo $row['power']." ".$row['intelligence']." ".$row['speed']." ".$row['reserve']; ?> </option>

<?php endwhile; ?>

</select>

 

 

Thanks for any advice!  Attached is a screen shot of the database.

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Hey all.. To ellaborate.

 

I'm trying to build a simple version of this game: http://thesurrealist.co.uk/monster

 

I have two characters, each with a name and a attribute. The player with the larger attribute wins, (if I can get it to that point, great.. I'd like to build on it).

 

I can get one drop down box to populate the character names.

 

I cannot get the correct attributes to populate (because they are table titles), I suspect I need to use mysql_field_name, but uncertain of where and how.

 

NEXT Step, I can't get the SECOND character NAME drop down box to populate, and I'm cutting/pasting the same <select> <object> code, but one thing at a time.

 

Attach is the picture of data base below is the code.

<?php
//require 'header.php';
//require 'footer.php';
mysql_connect('localhost', 'root', '');  //username and password of database
mysql_select_db('giantbattlemonsters') or die( "Unable to select database"); 

//Character
$sql = "SELECT * FROM game_char ORDER BY display_name ASC";
$results = mysql_query($sql) or die("Query failed with error: ".mysql_error());       // execute the query


//Game Play
$command ="SELECT power, intelligence, speed, reserve FROM game_char";
$options = mysql_query($command) or die("Query failed with error: ".mysql_error());


//	while ($row=mysql_fetch_array($results)){
//	$id=$row["id"];
//	$thing=$row["id"];
//	$options.="<OPTION VALUE=\"$id\">".$thing;
//	}

print_r($results);




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>8 Bit Battle</title>
<link rel="stylesheet" type="text/css" media="screen" href="characters_style.css " />




</head>

<body>

<div class="wrapper">	
<!-- <?php include 'header.php' ?>  -->

<div class = "content">
		<div class = "player1_char">
		<form name="player1">
			<h1>Character #1</h1>
			<p>
			<select name="id" style="font-size:20px;font-family:Arial;width:275px">
			<?php while($row = mysql_fetch_assoc($results)):?>
			<option value="<?php echo $row['id']; ?>"><?php echo $row['display_name']; ?></option>
			<?php endwhile; ?>
			</select>
			</p>
			<p>
			<select name="weapon" style="font-size:20px;font-family:Arial;width:275px">
			<?php while($row = mysql_fetch_assoc($options)):?>
			<option value="<?php echo $row['weapon']; ?>"><?php echo $row['power']." ".$row['intelligence']." ".$row['speed']." ".$row['reserve']; ?> </option>
			<?php endwhile; ?>
			</select>
			</p> 
		</div>

			<div class = "player2">

			<h1>Character #2</h2>
			<p>
			<select name="id2" style="font-size:20px;font-family:Arial;width:275px">
			<?php while($row = mysql_fetch_assoc($results)):?>
			<option value="<?php echo $row['id']; ?>"><?php echo $row['display_name']; ?></option>
			<?php endwhile; ?>
			</select>
			</p>
			<p>
			<select name="weapon2" style="font-size:20px;font-family:Arial;width:275px">
			<?php while($row = mysql_fetch_assoc($options)):?>
			<option value="<?php echo $row['weapon']; ?>"><?php echo $row['power']." ".$row['intelligence']." ".$row['speed']." ".$row['reserve']; ?> </option>
			<?php endwhile; ?>
			</select>
			</p> 
			<input type="button" onClick="SOMETHING HAPPENS HERE;" value="GO">
			</p>
		</form> 

			<form name="player2_power">
			<p align="center">

		</form>   

 

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Guest
This topic is now 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.