WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Function to do live population of HTML's <Select> tag from a Table
Categories : PHP, MySQL, HTML and PHP, Databases Update Picture
Pido Ayala
Date : May 21st 2001
Grade : 2 of 5 (graded 3 times)
Viewed : 8997
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Pido Ayala
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
/*

File        : fn_populateselectoptions.inc
Name        : function PopulateSelectOptions()
Author        : fernando ayala
Created        : May 4, 2001
Version        : 1.15

Description:
        This function takes several arguments and generates
        the <OPTION..>...</OPTION> HTML code fragment. A mysql_connect() is presumed
to exist already.

Arguments passed:
        $dbname                        (required) Database name
        $tblname                        (required) Table name
        $tblkeyvarname                (required) Name of table's key field
        $tblkeyvaluesname        (required) Name of column that describes key field (usually the
displayable value in the <select> options)
        $defval                        (optional) Default key value, if any. <select> displays
this value by default

Return Value(s)                        $success: returns 1 if query was successful, 0 if query
failed


Usage: To use this, construct the following code in your .PHP file --
        - - - - - - - - - - - - -
        <? require("fx_populateselectoptions.inc"); ?>
        <HTML>
        ...
        <BODY>
        ...
        <SELECT...>
        <?php
                PopulateSelectOptions (        $dbname,
                                                        $tblname,
                                                        $tblkeyvarname,
                                                        $tblvaluesname,
                                                        $defval
                                                 );
        ?>
        </SELECT>
        ...
        </BODY>
        </HTML>
        - - - - - - - - - - - - -

-----------
START FN:
-----------
*/

function PopulateSelectOptions ( $dbname, $tblname, $tblkeyvarname, $tblvaluesname,
$defval ) {

// Check passed arguments
        if ( empty($dbname) ) {
                echo "<!-- PopulateSelectOptions() Error: Database Name had no value --
>\n";
                return 0;
        }
        if (empty($tblname) ) {
                echo "<!-- PopulateSelectOptions() Error: Table name had no value -->\n";
                return 0;
        }
        if (empty($tblkeyvarname) ) {
                echo "<!-- PopulateSelectOptions() Error: Key Field name had no value --
>\n";
                return 0;
        }
        if (empty($tblvaluesname) ) {
                echo "<!-- PopulateSelectOptions() Error: Variable name for List Values
had no value -->\n";
                return 0;
        }

        $success=0;

// Set up table query
        $local_qry = "select * from " . $tblname;
        $localresult=mysql_db_query( $dbname, $local_qry );
        echo "<!-- DefVal passed was = " . $defval . " -->";
// Construct HTML code
        if ($localresult) {
                while( $row=mysql_fetch_array($localresult) ) {
                        echo "<option";
                        if ( isset($defval) ) {
                                if ( $row["$tblkeyvarname"]==$defval ) {
                                        echo " selected ";
                                }
                        }
                        if (is_string($tblkeyvarname)) {
                                echo " value='".$row["$tblkeyvarname"]."'>";
                        } else {
                                echo " value=".$row["$tblkeyvarname"].">";
                        }
                        echo $row["$tblvaluesname"];
                        echo "</option>\n";
                }
                $success=1;
        }

// Check if query was successful
        if (!$success) {
                if (!$localresult) {
                        echo "<!-- PopulateSelectOptions() Error: Could not access
database and/or table ".$dbname.".".$tblname.". -->\n";
                }
        }
        return $success;
}
/*
----------
END FN:
----------
*/
?>



html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Using the value of one select box to populate another with PHP and MySQL (Not JavaScript)
Categories : PHP, MySQL, HTML and PHP, Databases
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql
Categories : MySQL, HTML and PHP, PHP, Databases
This function will populate the options in a drop down HTML select list in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
How can i Preload a 'SELECT MULTIPLE'?
Categories : HTML and PHP, PHP, MySQL, Databases