PHP Classes
elePHPant
Icontem

File: SelectOptionsExample

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Muhamed Turkanovic  >  Select Options  >  SelectOptionsExample  >  Download  
File: SelectOptionsExample
Role: Example script
Content type: text/plain
Description: An example how to use it
Class: Select Options
Generate form select options from MySQL queries
Author: By
Last change:
Date: 4 years ago
Size: 4,445 bytes
 

Contents

Class file image Download
<?php

########################################################################################################################################
# copyright by MuhammedPasha, Muhamed Turkanovic #
# made december 2010 #
# #
# #
# How To: #
# Let us imagine we have a TABLE like this: #
# #
# CREATE TABLE IF NOT EXISTS `catalog_names` ( #
# `id` int(10) unsigned NOT NULL AUTO_INCREMENT, #
# `name` varchar(150) NOT NULL, #
# `user_id` varchar(150) NOT NULL, #
# `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, #
# PRIMARY KEY (`id`) #
# ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; #
# #
# #
# Inserting test data: #
# INSERT INTO `catalos_names` VALUES (1, 'CATALOG1', 1, NOW()); #
# INSERT INTO `catalos_names` VALUES (2, 'CATALOG2', 1, NOW()); #
# INSERT INTO `catalos_names` VALUES (3, 'CATALOG3', 1, NOW()); #
# INSERT INTO `catalos_names` VALUES (4, 'CATALOG4', 1, NOW()); #
# #
# And we want now to generate a select field with all the options which are in the table #
########################################################################################################################################

//The data and functions for opening the DataBase
include 'OpenDatabase.php';

//our Options Class
include 'Options.php';

//initializing the options clss
$options = new Options;


?>

<html>
<head>
<title></title>
</head>


<body>

    <h1>Form with autoGenerated Options for Select Fields</h1>


    <form>
   
    Test Input Field <input type="text" name="name"><br/>
   
    Test #1 SELECT Field
    <select name="chosen_catalog">
    <?php echo $options->showSelectOptions('name','id','catalog_names','','name','ASC',''); ?>
</select>
   
    Test #2 SELECT Field (with where statement)
    <select name="chosen_catalog">
    <?php echo $options->showSelectOptions('name','id','catalog_names','WHERE id > 2','','',''); ?>
</select>
   
    Test #3 SELECT Field (with prefered slected options)
    <select name="chosen_catalog">
    <?php echo $options->showSelectOptions('name','id','catalog_names','','name','DESC','CATALOG3'); ?>
</select>
   
   
    </form>
</body>


</html>