LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 05-13-2005, 06:46 PM   #1
camlinux
Member
 
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);
        
query_check($result);
        
$visible strtoupper($visible);
        
$id strtoupper($id);
    while(
$row mysql_fetch_assoc($result)){
                    
$id $row['$id'];
                    
$visible $row['$visible'];
                    echo 
"<option value=\"$id\">$visible</option>\n";
        }
        exit;

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, 07:02 PM   #2
camlinux
Member
 
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, 08:23 PM   #3
GarroteYou
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"
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 08:05 PM.

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