RE: check box help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks.  I tried that, and maybe I am doing something wrong with it, but
it didn't work.  What I did was I made a counter variable, $counter and
put it outside the while loop.  Then, inside the while loop, when it
makes a checkbox, I named the check box, $CheckBox[$counter], so that it
would put it at that spot in an array.  Then on the following page
(which the variables get posted to) I created a for loop to output all
the values of $CheckBox[].  I made the loop from 0 to < $counter, and it
still doesn't output anything.  Do I need to initialize the $CheckBox
array or something, if so, how do I do it?  Here is the modified code
that I used for this:

if (!mysql_connect($dbserver, $dbusername, $dbpassword)) {
        print 'Could not connect to mysql';
        exit;
    }
    $result = mysql_list_tables($dbname);    
    if (!$result) {
        print "DB Error, could not list tables\n";
        print 'MySQL Error: ' . mysql_error();
        exit;
    }
    mysql_free_result($result);
$counter=0;
$CourseInfo = mysql_query("SELECT * FROM $TableName");
while ($row=mysql_fetch_assoc($CourseInfo)) {
echo "<tr>
    <td width='3%' style='border-style: none; border-width: medium'>
    <input type='checkbox' name='$CheckBox[$counter]' value='ON'></td>
    <td width='7%' style='border-style: none; border-width: medium'>
    <p align='right'><b><font color='#800000'>Course:</font></b></td>
    <td width='18%' style='border-style: none; border-width: medium'
colspan='2'>
    <p align='center'><font color='#111111'>";
echo $row["ClassTitle"];
echo "</font></td>
    <td width='8%' style='border-style: none; border-width: medium'
colspan='2'>
    <b><font color='#800000'>Instructor:</font></b></td>
    <td width='15%' style='border-style: none; border-width: medium'>
    <p align='left'>";
echo $row["InstructorName"];
echo "</td>
    <td width='15%' style='border-style: none; border-width: medium'>
    <b><font color='#800000'>Course Description:</font></b></td>
    <td width='36%' style='border-style: none; border-width: medium'
colspan='2'>
    <p align='center'>";
echo $row["CourseDescription"];
echo "</td>
  </tr>
<tr>
<td width='100%' style='border-style: none; border-width: medium'
colspan='10'>
    &nbsp;</td>
</tr>
  <tr>";
$counter++;
}

//This is the loop code to output the $CheckBox[] array on the following
page:
for($i=0; $i < $counter; $i++) {
echo $CheckBox[$i];
echo "<br>";
}


The output of the following page is just blank.  It doesn't output
anything.  Please help, and thanks a lot for your response from before.

Matt 


-----Original Message-----
From: Rich Hutchins [mailto:rhutchin@rochester.rr.com] 
Sent: Thursday, January 30, 2003 9:35 PM
To: Matt; php-db@lists.php.net
Subject: RE:  check box help

If I understand your question correctly, you really don't have to do
much to
accomplish what you're looking to do. If you name your checkboxes as an
array ($myCheckboxes[]) then, when the form data is submitted, all of
the
$myCheckboxes[] will be passed as an indexed array called, surprisingly
enough, $myCheckboxes ($myCheckboxes[0], $myCheckboxes[1], etc.). In the
resulting script, you need only iterate over them with a control
structure
such as a for() loop.

Hope this helps.

-----Original Message-----
From: Matt [mailto:mpalermo@vt.edu]
Sent: Thursday, January 30, 2003 4:58 PM
To: php-db@lists.php.net
Subject:  check box help


Hey can anyone help me out?  I am a bit of an amatuer at this.  Here is
my
problem:

I have an SQL table with a three fields in it.  They are ClassTitle,
InstructorName, and CourseDescription.  I am setting up a table that
lists
the records with a check box in front of it.  Then if the user checks
the
box, it will give him access to that data(which I have set up in a
separate
table).  The problem is that I don't know how to name the check box,
since
it goes through a while loop.  I want the user to be able to check more
than
one box, if it is neccessary.  But I don't know how to name the check
boxes
uniquely (one check box for each record in the table), so that once they
are
checked, I can work with it later on the next page.  I have inserted a
chunk
of the code I am working on for it.  Please help me if you can.  Thanks.

if (!mysql_connect($dbserver, $dbusername, $dbpassword)) {
        print 'Could not connect to mysql';
        exit;
    }

    $result = mysql_list_tables($dbname);

    if (!$result) {
        print "DB Error, could not list tables\n";
        print 'MySQL Error: ' . mysql_error();
        exit;
    }
    mysql_free_result($result);

$CourseInfo = mysql_query("SELECT * FROM $TableName");
while ($row=mysql_fetch_assoc($CourseInfo)) {
echo "<tr>
    <td width='3%' style='border-style: none; border-width: medium'>
    <input type='checkbox' name='$CourseCheck' value='ON'></td>
    <td width='7%' style='border-style: none; border-width: medium'>
    <p align='right'><b><font color='#800000'>Course:</font></b></td>
    <td width='18%' style='border-style: none; border-width: medium'
colspan='2'>
    <p align='center'><font color='#111111'>";
echo $row["ClassTitle"];
echo "</font></td>
    <td width='8%' style='border-style: none; border-width: medium'
colspan='2'>
    <b><font color='#800000'>Instructor:</font></b></td>
    <td width='15%' style='border-style: none; border-width: medium'>
    <p align='left'>";
echo $row["InstructorName"];
echo "</td>
    <td width='15%' style='border-style: none; border-width: medium'>
    <b><font color='#800000'>Course Description:</font></b></td>
    <td width='36%' style='border-style: none; border-width: medium'
colspan='2'>
    <p align='center'>";
echo $row["CourseDescription"];
echo "</td>
  </tr>
<tr>
<td width='100%' style='border-style: none; border-width: medium'
colspan='10'>
    &nbsp;</td>
</tr>
  <tr>";
}


Thanks,

Matt



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux