Jump to content

Recommended Posts

iii how to get value from database for dropdown list

 

<select class="special" name="year">
<option value="" selected>Staff Name
<option value="<?php echo $row['staff_name']?>" ><?PHP while($row = mysql_fetch_assoc($result))
			                  {
						echo $row['staff_name'];
                                                                      }?> 
</select>

this is code that i have done. it appear but the name not go down like JosephJoLinaAlex

suppose like this

 

Joseph

Jo

Lina

Alex

Link to comment
https://forums.phpfreaks.com/topic/123867-solved-drop-down-list-from-database/
Share on other sites

take a look at this, maybe it will help out some: http://phpsnips.com/snippet.php?id=10

 

You also need a closing option tag:

 

<option value="something">Some Text</option>
<option value="something">Some More Text</option>
<option value="something">Etc...</option>

i use this and seems to be exactly what your looking for

<select name="Cat">
<?php
// includes
include("../template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query				
$query = "SELECT * FROM galleryname";				
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
<option value="<? echo $row->Gallery; ?>"><? echo $row->Gallery; ?></option>
<?php
}
}
// if no records present
// display message
else
{
?>
<option>No option</option>
			<?php
			}
			// close database connection
			mysql_close($connection);
			?>

i use this and seems to be exactly what your looking for

<select name="Cat">
<?php
// includes
include("../template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query				
$query = "SELECT * FROM galleryname";				
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
<option value="<? echo $row->Gallery; ?>"><? echo $row->Gallery; ?></option>
<?php
}
}
// if no records present
// display message
else
{
?>
<option>No option</option>
			<?php
			}
			// close database connection
			mysql_close($connection);
			?>

 

i... thank you for your info. i got it..........

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.