CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to load a pulldown box with values from a db

 



ebelaski
Deleted

Dec 19, 2000, 11:03 AM

Post #1 of 3 (167 views)
How to load a pulldown box with values from a db Can't Post

I have created an HTML form using Perl/CGI_pm and
would like to use values for the pull down boxes from a
MYSQL database table. How do you load the values in to
the list instead of using a static list.
This seems like a fairly common process yet I cant seem to
find any code snipit...
thanks for the help.



Maebius
Novice

Dec 29, 2000, 8:29 AM

Post #2 of 3 (142 views)
Re: How to load a pulldown box with values from a db [In reply to] Can't Post

Well, I have no real experience in SQL, but I have a virtual postacard script that dynamically generates a pulldown list based on the available *.gif files in the image directory...
This is just a snippet from the part of the code that generates the Webpage where you choose the picture and enter name/email/message/etc. Perhaps it can give you some small idea to base your script off of.

If you want to see this script in action point your browser to:
http://www.everthorn.net/postcards.shtml
(just created so forgive the cheesy interface. I'll work on cosmetics after functionality) The 'shtml' is so *eventually* I can put some fancy stuff on the webpage without re-updating all my links.

<xmp>
Print <<"EOF";
<form ....>Other form stuff here...
<pre>Image File to use:<select name="ImageFile"
size="1">
EOF

# open the images directory
$path='../htdocs/images/postcards';
opendir(DIR, "$path") or die "$!";
@dir=readdir DIR;
closedir(DIR);
# the array @dir now contains a list of all GIF files.

foreach $file (@dir){
if ($file =~ /\.gif/){
print "<option>$file<\/option>";
}
}

print <<"EOF";
</select></pre>
</td>
<td><pre>Type your message here:
<textarea name="TextMsg" rows="6" cols="35">$FromWeb{TextMsg}</textarea></pre>
</td>
<td> </td>
</tr><td><input type="submit" name="Preview" value="Preview your card"></td>
</table>
</form>
</xmp>





Enjoy!
-Maebius


living life -umop apisdn-
maebius@everthorn.net


Maebius
Novice

Dec 29, 2000, 8:31 AM

Post #3 of 3 (142 views)
Re: How to load a pulldown box with values from a db [In reply to] Can't Post

Well, I have no real experience in SQL, but I have a virtual postacard script that dynamically generates a pulldown list based on the available *.gif files in the image directory...
This is just a snippet from the part of the code that generates the Webpage where you choose the picture and enter name/email/message/etc. Perhaps it can give you some small idea to base your script off of.

If you want to see this script in action point your browser to:
http://www.everthorn.net/postcards.shtml
(just created so forgive the cheesy interface. I'll work on cosmetics after functionality) The 'shtml' is so *eventually* I can put some fancy stuff on the webpage without re-updating all my links.


Quote
Print <<"EOF";
<form ....>Other form stuff here...
<pre>Image File to use:<select name="ImageFile"
size="1">
EOF

# open the images directory
$path='../htdocs/images/postcards';
opendir(DIR, "$path") or die "$!";
@dir=readdir DIR;
closedir(DIR);
# the array @dir now contains a list of all GIF files.

foreach $file (@dir){
if ($file =~ /\.gif/){
print "<option>$file<\/option>";
}
}

print <<"EOF";
</select></pre>
</td>
<td><pre>Type your message here:
<textarea name="TextMsg" rows="6" cols="35">$FromWeb{TextMsg}</textarea></pre>
</td>
<td> </td>
</tr><td><input type="submit" name="Preview" value="Preview your card"></td>
</table>
</form>




Enjoy!
-Maebius


living life -umop apisdn-
maebius@everthorn.net

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives