Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-13-2005, 07:46 PM   #1
Registered: Feb 2003
Location: north dakota
Distribution: Gentoo, Debian
Posts: 90

Rep: Reputation: 15
PHP: html Form Select function problem

I've been trying to figure this out for the past couple of days, but I'm stumped. I'm writing a simple function that will create a select box for an HTML form using data from a mysql database. I want to be able to give the function 3 variables and have it create the options for the select. Here is what I have so far
PHP Code:
function select_values($table,$visible,$id){
$query sprintf("SELECT * from $table");
$result mysql_query($query);
$visible strtoupper($visible);
$id strtoupper($id);
$row mysql_fetch_assoc($result)){
$id $row['$id'];
$visible $row['$visible'];
"<option value=\"$id\">$visible</option>\n";

And here is the call to it in my page
PHP Code:
            <?php select_values(MB,MB_DESC,MB_ID);?>
The echo statement works except the variables do not display. I get this
<option value=""></option>
in the source of my document.
If I replace $id and $visible with MB_ID and MB_DESC inside the function it works flawlessly.

Thanks for you help
Old 05-13-2005, 08:02 PM   #2
Registered: Feb 2003
Location: north dakota
Distribution: Gentoo, Debian
Posts: 90

Original Poster
Rep: Reputation: 15
I figured it out simple simple simple, just needed to not put the variables in quotes.
Old 05-15-2005, 09:23 PM   #3
LQ Newbie
Registered: Feb 2003
Location: Bay Area
Distribution: RH 8.0
Posts: 10

Rep: Reputation: 0
You mean like this?

PHP Code:
echo "<option value=\"" $id "\">" $visible "</option>\n"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
php function to open an html page prabhatsoni Linux - Software 2 06-14-2005 12:32 AM
PHP:Unable to post variables from html form to mysql database vikram_cvk Linux - Software 1 09-29-2004 04:01 PM
PHP and HTML Form Post Savahn Programming 12 06-30-2004 04:15 PM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 09:02 PM
problem with html form meluser Linux - Software 4 03-15-2003 01:28 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration