#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    Just had someone ask me to create this, thought I would share it. Enjoy.

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    <?php
    function createSelect ( $Sname, $table, $any = 0, $select_id="" ) {
    # $Sname is the name to be applied to the select control.
    # $table is the name of the table to query.
    # NOTE: This function assumes you are using a lookup table that has 2 fields (id,name) or you only name those 2 fields in your sql statement.
    # $any 0=Without the "Any" option, 1=With the "Any" option, this is a NULL value.
    # $curr_id is used to set the "SELECTED" flag on the select control.
    //Global.inc is where you have all your database variables.
    include("../etc/global.inc");
    $dbh = mysql_connect($host,$user,$pass);
    mysql_select_db($dbname);
    $sql = "SELECT * FROM $table";
    $results = mysql_query($sql);
    printf("<select name="$Sname">n");
    if ($any == 1) {
    printf("<option "">Anyn");
    }
    while ($row = mysql_fetch_array($results)):
    $id = $row["id"];
    $name = $row["name"];
    if ($id == $select_id) {
    printf("<option SELECTED value="$id">$namen");
    } else {
    printf("<option value="$id">$namen");
    }
    endwhile;
    printf("</select>n");
    }
    ?>

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Example
    //"Type" is the name of the created select box.
    //"type" is the name of the table to query.
    //1 is the flag to set a null value for an option called "Any" this is hand for searching. This argument is optional.

    <form method=post action=somescript.php>
    Please select your type:<?php createSelect("Type","type",1);?><br>
    <input type=submit name=type value="Submit">
    </form>
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    -Ray

    Disclaimer: I take no responsibility for any damage, fire or injury this function may, and likely will cause.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    Just had someone ask me to create this, thought I would share it. Enjoy.
    >>


    Ray,
    what is the use of this script?You are not explaining that..

    just visit the following link.you can see the similar logic in a better way...
    http://www.phpbuilder.com/columns/tim19991124.php3




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."


    [This message has been edited by Shiju Rajan (edited August 02, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    Shiju : Between the title and the comments I think it is obvious what the function does. I appreciate your zeal for the promotion of www.phpbuilder.com and all but I was just sharing some code I worked on, not meant to be the "best" way to do it, just an example for anyone who cares to take a look at it.

    I'll try to refrain from posting my inferior code on this board ;-)


    -Ray
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    I'll try to refrain from posting my inferior code on this board ;-)
    >>


    Ray,
    sorry ,Actually i didn't mean that your code is bad.That is really Good!!.You should post your inferior codes here.From that people like me will learn alot.


    <<
    I appreciate your zeal for the promotion of www.phpbuilder.com
    >>

    No,No, please don't think in that way..i don't have to promote anybodies site..even i am not getting time to promote my sites(i have couple of sites...i have a career portal http://www.jobxyz.com .i invite you to visit my career portal jobxyz.com).

    -----------------

    sorry again!!!




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    Sorry Shiju, did not mean to be so sarcastic, just been a long day and the end is no where in site. Gotta love when you get 6 week projects with a 2 week deadline :-)


    -Ray

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 17th, 2004, 12:21 AM
  2. Updating text fields from dynamic SQL select box?
    By Trent Hatred in forum HTML Programming
    Replies: 3
    Last Post: February 6th, 2004, 11:34 AM
  3. Help with SELECT boxes
    By MorgenBajer in forum HTML Programming
    Replies: 4
    Last Post: February 5th, 2004, 06:43 AM
  4. dynamically created check boxes
    By wduffee in forum PHP Development
    Replies: 3
    Last Post: February 3rd, 2004, 02:10 PM
  5. outputting query results from a function?
    By theverychap in forum PHP Development
    Replies: 4
    Last Post: February 2nd, 2004, 08:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo