[PHP] RE: newbie Dynamic Drop down lists using mysql

2003-04-03 Thread Bobby Rahman


Hiya

Im looking for any tutorials/snippets of code to show me how to code a 
dynamic drop down box/list in a php form.

e.g a drop down menu of all current users (I assume this will need to 
connect to mysql db and select all usernames from table user and place in 
the menu.

here what I have so far
?
$connection = db_connect();
$querystring = (select username from user);
$db_result = mysql_query($querystring);
(if mysql_num_rows($db_result))
{
 while ($row = mysql_fetch_row($db_result))
  {
 print(option value=\$row[0]\$row[0]/option);
  }
}
else
{
print(option value=\\No users created yet/option);
}
?

Any URLS will be much appreciated.

Thanks

Bob

_
Express yourself with cool emoticons http://www.msn.co.uk/messenger
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] RE: newbie Dynamic Drop down lists using mysql

2003-04-03 Thread Daevid Vincent
Not that this hasn't been coverd a million times already Bobby -- check the
archives...

   function ListboxMatch($size, $name, $query, $matchtothis) 
   {
   $items = 0;
   //echo BR.$query.BR;
   if ( $qry = mysql_query($query) )
   {
   if (mysql_num_rows($qry)  0)
   {
echo SELECT SIZE='.$size.' NAME='.$name.'
.$INPUT.\n;
if ($size == 1) echo \tOPTION
VALUE=''\n;
while (list($value, $text, $description) =
mysql_fetch_row($qry))
{
$items++;
echo \tOPTION VALUE='.$value.';
if ($value == $matchtothis) { echo 
SELECTED; }
echo ;
echo stripslashes($text);
if ($description) echo 
(.stripslashes($description).);
echo /OPTION\n;
}
  echo /SELECT;
   }
   else echo No data for Listbox\n;
   mysql_free_result($qry);
   }
   else echo Listbox cannot be built because of an invalid
SQL query.;
   
   return $items;
   } // end ListboxMatch

 -Original Message-
 From: Bobby Rahman [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, April 03, 2003 5:34 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] RE: newbie Dynamic Drop down lists using mysql
 
 
 
 
 
 Hiya
 
 Im looking for any tutorials/snippets of code to show me how 
 to code a 
 dynamic drop down box/list in a php form.
 
 e.g a drop down menu of all current users (I assume this will need to 
 connect to mysql db and select all usernames from table user 
 and place in 
 the menu.
 
 here what I have so far
 ?
 $connection = db_connect();
 $querystring = (select username from user);
 $db_result = mysql_query($querystring);
 
 (if mysql_num_rows($db_result))
 {
   while ($row = mysql_fetch_row($db_result))
{
   print(option value=\$row[0]\$row[0]/option);
}
 }
 else
 {
 print(option value=\\No users created yet/option);
 }
 
 
 ?
 
 Any URLS will be much appreciated.
 
 Thanks
 
 Bob
 
 _
 Express yourself with cool emoticons http://www.msn.co.uk/messenger
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RE: newbie Dynamic Drop down lists using mysql

2003-04-03 Thread Sebastian
This is how i make my drop downs, see if this help...

 echo form action=\page.php\ method=\get\
 select name=\category\
  option value=\-1\show all;

  $results = @mysql_query(SELECT * FROM table);
   while($row = mysql_fetch_row($result)) {
 echo option value=\$row[0]\$row[0]; 
   }
   echo /selectinput type=\submit\ value=\submit\/form;


cheers,
- Sebastian

 -Original Message-
 From: Bobby Rahman [mailto:[EMAIL PROTECTED] 

|  Hiya
|  
|  Im looking for any tutorials/snippets of code to show me how 
|  to code a 
|  dynamic drop down box/list in a php form.
|  
|  e.g a drop down menu of all current users (I assume this will need to 
|  connect to mysql db and select all usernames from table user 
|  and place in 
|  the menu.
|  
|  here what I have so far
|  ?
|  $connection = db_connect();
|  $querystring = (select username from user);
|  $db_result = mysql_query($querystring);
| 
| (if mysql_num_rows($db_result))
|  {
|while ($row = mysql_fetch_row($db_result))
| {
|print(option value=\$row[0]\$row[0]/option);
| }
|  }
|  else
|  {
|  print(option value=\\No users created yet/option);
|  }
|  
|  
|  ?
|  
|  Any URLS will be much appreciated.
|  
|  Thanks
| 
|  Bob


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php