Web Development Logs
Find articles, news and reviews about latest technologies.


Welcome Guest !
please login or register a new free account.


Home | Archives | Submit Article | Top Rated | Advance Search | Contacts Us | Rss Feeds

    Main Categories
» Free downloads
» General Blog
» Google Adsense
» Scripting languages
» Search Engines
» Web Designing

  More Options
» Most read articles
» Most rated articles

   Subscription
Subscribe now and receive free articles and updates instantly.
» Your name » Your Email

titles description    advance search
Published : April 29, 2006 | Author : Ali Roman
Category : Scripting languages | Total Views : 6413 | Rating :

  
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

Creating table with MySQL and PHP
Retreiving data from MySQL table

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..




1 2 3 4 5
please rate this article     Poor
Excellent    
Most viewed articles in Scripting languages category

Retrieving data from MySQL database using php
Creating simple contact form using swishmax and php
Creating dynamic combo list with PHP and MySQL
Creating simple percentage preloader with swishmax
Saving data to a text file with swishmax and php
Most recent articles in Scripting languages category

Saving data to a text file with swishmax and php
Creating dynamic combo list with PHP and MySQL
Retrieving data from MySQL database using php
Establishing connection with MySQL using php
Creating table using MySQL database

 Visitor's Comments !

there are no comments...


    Random Pick
This is pretty bsaic tutorial demonstrating how to load data form an external text file. This is very handy when you dynamically update your website rather than editing the flash files. I tried my best to explaing with images I hope it will help you.

    Statistics
» Total Articles
72
» Total Authors
96
» Total Views
116307
» Total categories
6

Delete cookies set by this site | Top   

Article Manager by Flaxweb
Copyright 2006 © Flax Article Manager v1.1