creating dynamic combo in PHP and MySQL.. - PHP / MySQL Tutorials
 
  Buy Ebooks, Video Games, DVDs, Electronics and more !
Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads Make Money Online Blog . Free Image and Photo Sharing and Hosting

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Free image hosting
   Web Design Pakistan
   Swish Templates
   SWiSH Climax
   Talkfreelance Community
   Template Desire
   Lite boards
   Script Sector
   GimpTalk
   13dots
   Idea Designs
   PHP Cafe
   Sposatoettore
   Free swishmax templates
   Swishzone

Manage your site with Flax Article Content Management System
creating dynamic combo in PHP and MySQL..
Category : PHP / MySQL | Level : Intermediate | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Tutorial : Recieving data (from MySQL) and displaying in a combo (drop down list box).
Level : Intermediate

This is very basic tutorial, actually someone requested me through PM but I didnt have time to repond him quickly, so here it is now.I assume you already know how to insert data into tables.or read the following tutorial before reading this

Retrieving data from tables
Creating Table and Data Insertion

Ok - I assume you have already created a table called category..
you have added a few categories into this table, e.g swishmax, swish 2, flash mx and photoshop.
the field name is cat_name which we will use in next step to fetch data.

here is the quickest way.

echo'<select name="categories">';

$res=mysql_query("select * from category");
if(mysql_num_rows($res)==0) echo "there is no data in table..";
else
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[cat_name]</option>";
}
echo'</select>';

Description of line echo'<select name="categories">';
this is simple text for creating a combo in html, we give it a name becuase we will have to use this name again when any category is selected, for example someone has seelcted the flash mx category, then the variable categories will have a value flash mx..

Description of line $res=mysql_query("select * from category");
this is simple query for fetching all fields form table. But you can use different if you dont want to fetch all fields, you may use WHERE clause to make it more specific.

Descrition of if(mysql_num_rows($res)==0) echo "there is no data in table..";
this will simply tell if there is any data in the table or the table is empty.

for() loop will simply fetch all the categories added into table and display.

echo'</select>'; is simply closing tag for the combo box.

I hope it will help someone to figure how is a dyanmic combo box is created while recieveing data from MySQL.

cheers
- Ali..


© 2002-2005 Flaxweb Network | Article Manager | Gimp Tutorials Library | RAD C++ Library | Free C/C++ Sourcecode |
Sites of interest : Web Design Blog | Swish Templates | Swishmax Ebook | Photoshop Templates | Gimp Tutorials | Text Forum | Make Money Online