LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 06-01-2005, 11:29 AM   #1
domquem
LQ Newbie
 
Registered: Jul 2004
Location: WASHINGTON,DC AREA
Distribution: SUSE LINUX 9.1
Posts: 17

Rep: Reputation: 0
HELP!! Perl script to display drop down menu


Perl script to display drop down menu on webpage after reading menu items from a mysql table.

I have a mysql table with a field called Course_name - has like 30 course names in it.
Now i need help as i am very green in perl, with a very simple script to access read the table then fetch the course names which will then need to e dispalyed dynamically in a webpage as Drop Down menu / combo box
.
All the30 course menu items should be displayed in the page after which someone can select any option and have the info about the particular choice they select being displayed.

Thanks for helping, will really appreciate.
 
Old 06-01-2005, 12:44 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Is this what you are looking for?
Code:
my $sth = $dbh->prepare("SELECT course_name FROM table");
$sth->execute();
print "<select>";
while ($course = $sth->fetchrow_array()){
 print "<option>$course</option>";
}
print "</select>";
 
Old 06-01-2005, 12:56 PM   #3
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
Some good things to look up are 1) how to connect to a mysql table in Perl (use the DBI module, makes things very easy, as david_ross showed), and 2) how to dynamically write HTML content. Basically, what you'll need to do is make your web page a perl script (instead of a .html file), which does a whole lot of "print" statements. You can't embed perl snippets in a web page the same way you can with php.

I've a simple little Hello, World! perl script on my website: http://www.cybermenology.com/cgi-bin/stuff.pl

The code is this, and should give you a good starting point for writing your page:
Code:
#!/usr/bin/perl
print "Content-type: text/html\r\n\r\n";

print "<HTML>";
print "<HEAD><TITLE>Hello, world!</TITLE></HEAD>";
print "<BODY>";
print "Hello, world!";
print "</BODY>";
print "</HTML>";


exit(0);
The first 2 lines are required; leave 'em in there or things won't display correctly. Other than that, just print the HTML page as you want it to appear, and embed the database code where you want to populate your drop-down list. If it's in a form, put the option box inside of a form and assign the form whatever action you want taken; once the page is written, the browser doesn't know whether it is rendering a perl page or an html one, and it will act just like a normal html form would.

Edit: a good tutorial starts here.

Last edited by rose_bud4201; 06-01-2005 at 01:24 PM.
 
Old 06-03-2005, 11:26 AM   #4
domquem
LQ Newbie
 
Registered: Jul 2004
Location: WASHINGTON,DC AREA
Distribution: SUSE LINUX 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Many thanks guys ...this is exactly what i needed.
I will surely start coding in perl right away.
 
  


Reply



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
Disable F10 for menu drop down titanandrews Linux - General 1 03-30-2011 12:31 PM
How can I create KDE/Gnome menu shorcut via perl script? mf1234 Programming 1 08-16-2005 05:46 PM
Question about drop down menu and Java Hockeyfan Programming 1 06-03-2005 11:11 PM
Firefox + drop down menu arrows Ateo Linux - Software 0 05-07-2005 04:19 PM
PERL: populating a drop down box from the DB vous Programming 3 08-27-2003 07:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:19 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration