Welcome! Log In Create A New Profile

Advanced

Course Checkbox

Posted by 77928490 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Course Checkbox
April 28, 2013 03:14AM
Hi again, trust you are all well.

My query is about holding the check / uncheck value for a checkbox for the assignment.

Below is an extract from the tutorial example:-

Language: PHP
if (isset($_POST[';Submit1';])) {   if (isset($_POST[';ch1';])) { $ch1 = $_POST[';ch1';];   if ($ch1 = = ';net';) { $ch1 = ';checked';; } }

My code looks like the following:-

Language: PHP
$SQL="SELECT * FROM course"; $result=mysql_query($SQL); while($db_field=mysql_fetch_assoc($result)){   if (isset($_POST[';ch';.$db_field[';cid';]])){   $check_course[$db_field[';cid';]] = ';checked';; } }

The isset() lines of code ito the checkbox refer to my query. Essentially I can't read in the value. Get an undefined index error. Maybe someone can see the obvious mistake. I hope so.

Alternatively does anyone have a few suggestions / tips when using checkboxes.

Thanks in advance.

Ian
avatar
Mac
Re: Course Checkbox
April 29, 2013 07:55AM
Undefined index is a notice, not an error. Do a search on it in the forums - it has been addressed.

I don't get the use of the sql query here - there always will be a result? You need to add a where statement, an if a row exists then present the check box as either selected or not. Except if I misunderstand what you are truing to achieve...
avatar Re: Course Checkbox
April 29, 2013 10:47AM
This is what I did with my checkbox

Language: PHP
<td></td><td><label>Share Info:</label><input type="checkbox" name="studSHARE" . <?php echo ($studShare == ';1';)?';checked';:';';?> . tabindex="19"></td>

The value 1 comes from my database where, if it is checked the value '1' gets stored in the database.
Re: Course Checkbox
May 01, 2013 01:42PM
Alex B did it run..?

78009855
Re: Course Checkbox
May 02, 2013 12:23AM
Hi all,

Thanks to everyone for their comments. Found a solution. Yay!!!!

Essentially I checked to see which checkbox was checked using isset() function.

Then set that checkbox to checked.

Used arrays. Below is the code used.

Language: PHP
if (isset($_POST[$check_id[$i]])){ $check_course[$i] = ';checked';; ....... }

Quite simple in the end.

cheers

spinning smiley sticking its tongue out
avatar Re: Course Checkbox
May 02, 2013 12:15PM
Works great!!


solomzi mkhela Wrote:
-------------------------------------------------------
> Alex B did it run..?
Sorry, only registered users may post in this forum.

Click here to login