Results 1 to 8 of 8

Thread: populate_select()

  1. #1
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Question populate_select()

    in php what is the function of populate_select()?

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Sorry, but we're going to need more information than that to help you, there is no inbuilt function in php called populate_select(), so are you referring to a user defined function?
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #3
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    That expression is like that
    Code:
    <?php populate_select("countries","countryid","country",$education->countryid); ?>
    Last edited by keyboard; 10-12-2012 at 12:08 AM. Reason: Format: Code Tags

  4. #4
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    I double checked the list of inbuilt functions, there is no function called populate_select, the function must be user defined, so we'll only be able to help you if we have the code for the function.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  5. #5
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    yes i found that user defined function which is like
    Code:
    <?php
    function populate_select($table,$fields_id,$fields_value,$selected){
    	$conn=db_connect(HOST,USER,PASS,DB,PORT);
    	$sql="Select $fields_id,$fields_value From $table Order By $fields_value";
    	$results=query($sql,$conn);
    	while ($row = fetch_object($results)){
    		$SelectedField=($row->$fields_id==$selected) ? " selected" : "";		
    		echo "<option value='" . $row->$fields_id ."'". $SelectedField . ">" . $row->$fields_value . "</option>";
    	}
    	free_result($results);
    }
    ?>
    Last edited by keyboard; 10-12-2012 at 12:09 AM. Reason: Format: Code Tags

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    It selects some info from a DB and displays it. It's not very well-written, however. If you need to do this, I'd recommend a different method.

  7. #7
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    ^ more specifically than that, It populates a <select> tag (drop down options)
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    it's intended to, yes.

    some specific downfalls this function has:
    1. creates a new DB connection for *every* use
    2. does not validate or sanitize data used in the query
    ......(I don't know how data is passed to the function, but if it comes from the user, this is a serious problem)
    3. doesn't check if there was an error, or if any results were actually returned
    4. outputs a load of un-escaped HTML (of unknown size) right in the middle of the function
    ......what happens if there's a < or " (or worse yet, a whole <tag>) in the results?
    ......what happens if there's a script error later on?
    ......what happens if there's no opening/closing <select> tag outside this function?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •