List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:April 22 2000 2:12pm
Subject:Re: Getting Query for Checkboxes
View as plain text  
Thanks for the reply and I think I can get that to work for me.  Actually, the
first form will be filled out for each lab so I will only grab one field which
will be the join for the two tables - probably the lab building abbreviation and
room number eg. wey210  - So I will prabably use a fetch row array to grab the
joiner field and also the actual lab name - Maybe a hash array would be nice so
that on the second form I can display the actual name of the lab, but pass only
the joiner field along with the checkbox info.

Would you use a hash array on this? or just call from the database?
Here is what I think I can do in the second form:
my $dbh = Mysql->connect("localhost", "database", $username, $password);
my $sth = $dbh->Query("select field1 from first_table")
or die $Mysql::db_errstr;

my @arr=();
while (@arr = $sth->fetchrow)
print $query->checkbox (-name=>$field1, -value=>'checked':'')$field1;

Ok, but I do I link the checked/unchecked to each individual field1?  Because
when I query the
all the labs that have certain software I want to retrieve a list of labs with
checkboxes next to them.
so I need to relate the labname with the checkbox in the second table - instead
of checked and unchecked can I have field1 and nothing?  so that the checkboxes
value will be the lab name?

Thanks for all the help.


benjamin-weiss wrote:

> > -----Original Message-----
> > From: Douglas Brantz [mailto:brantzdr@stripped]
> > Sent: Friday, April 21, 2000 7:02 PM
> > To: mysql@stripped
> > Subject: Getting Query for Checkboxes
> <snip>
> > I am creating a mysql database with two tables.  I want to be able to
> > have two different web forms to populate the tables.
> > The first form will be standard, but the second form I need to be able
> > to grab a field from the first table with a fetchrow array to create a
> > list of checkboxes (checked/unchecked) and the data from the
> > first table
> > next to the checkboxes.  This way the number of checkboxes with data
> > will grow or shrink depending on the data from the first table.  Does
> > this make sense?
> If I understand, you want a variable number of check boxes based upon which
> of several fields/columns in the first table are actually populated.  In
> other words, if you have table one:
> CREATE TABLE foo (id int, field1 int, field2 int, field3 int)
> and then, only have check boxes on the second form for those fields that
> actually have something in them, right?
> Yes, this is possible.  Remember that I'm working in perl, not PHP3, but
> what you want to do is something like:
> if ($field1 > 0) {
>         print qq{<INPUT TYPE="checkbox" NAME="field1"> $field1</INPUT>};
> }
> or some such.  The reason that you want to name the checkbox the same as the
> field is to make it easier to grab the data from the form and shove it back
> and forth to/from the database.  (Hint, check field bindings in the perl
> DBI.)
> > If not can I create a drop down menu that allows multiple selections?
> Yes, and I've done it, though I can't remember the special HTML setting on
> the listbox allowing multiple selections.  It's tricky.
> > This is for an educational institution and I want the first table to
> > have computer lab info and the second table will hold
> > software info- one
> > form per software product and on the (second form) -software form, I
> > want to have a "where is the software available" area - I thought
> > checkboxes next to each lab name would be the way to go because its
> > easier to see, but wasn't sure if I could grab the lab names from the
> > first form and place checkboxes next to each lab name.  This will be a
> > CGI-Perl script form.  Maybe a drop down menu with multiple selections
> > might be easier?  Its a big project for the holiday and any
> > suggestions
> > - other than get a life would help.
> Actually, it would probably be easier (and make more sense to your users) if
> you just always put the checkboxes out there, and only checked the ones that
> had data.  For instance:
> print qq{<INPUT TYPE="checkbox" NAME="field1"}, field1 > 0 ? "CHECKED" : "",
> ">Lab 1</INPUT>";
> would work nicely.
> Ben
> ----------------------------
> 45th Infantry Brigade (SEP)
> Signal Platoon Leader

Getting Query for CheckboxesDouglas Brantz22 Apr
  • RE: Getting Query for Checkboxesbenjamin-weiss22 Apr
    • Re: Getting Query for CheckboxesDouglas Brantz22 Apr
      • RE: Getting Query for Checkboxesbenjamin-weiss22 Apr