Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Ezilon Directory   I Sell Pagerank   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2007, 05:40 AM   #1 (permalink)
Junior Member
 
white10's Avatar
 
Join Date: 10-05-06
Posts: 23
iTrader: 0 / 0%
Latest Blog:
None

white10 is liked by many
Radio Buttons and mysql

Hi Guys

I am loading a test from a database, which contain all the questions and possible answers, Now what i want to do is display the possible answers as radio buttons and check if the user selected the correct radio button.(i will use the variable $cat_letter to check the value of the radio button selected.)

I want to checked if each radio button selected is equal to $cat_letter and then add 1 to it if not add 0 and conitue with the while loop

Can any of you guys be of help to me...

Code:
<?php session_start(); include "db_connect.php"; $get_cats = "select * from tests1"; $get_cats_res = mysql_query($get_cats) or die(mysql_error()); if (mysql_num_rows($get_cats_res) < 1) { $display_block = "<P><em>Sorry, no categories to browse.</em></p>"; } else { $display_block .= " <table width='574' border='1' cellpadding='0' cellspacing='0' > <tr> <td> <h2>$cat_title </h2> </td> </tr>"; $hold[]; while ($cats = mysql_fetch_array($get_cats_res)) { $cat_id = $cats[id]; $cat_description = stripslashes($cats[description]); $cat_letter = stripslashes($cats[letter]); $cat_answer_a = stripslashes($cats[answer_a]); $cat_answer_b = stripslashes($cats[answer_b]); $cat_answer_c = stripslashes($cats[answer_c]); $display_block .= "<tr> <td width ='30' class='style17'>$cat_id <td/> <td align='center' width ='294' bgcolor='white' class='style19'>$cat_description<td/> <td width ='80'> $cat_answer_a <INPUT TYPE='radio' NAME='one' VALUE='a' 'checked' > $cat_answer_b <INPUT TYPE= 'radio' NAME=\"one\" VALUE=\"b\" > $cat_answer_c <INPUT TYPE= 'radio' NAME=\"one\" VALUE=\"c\" > <td> </tr>"; } $display_block .= "</table>"; } ?>
white10 is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 07-09-2007, 11:16 PM   #2 (permalink)
Inactive
 
Join Date: 07-09-07
Posts: 1
iTrader: 0 / 0%
Latest Blog:
None

bsboard is liked by many
What you are going to want to do is numerically name each radio button set, which coincides with the row from the database. Something like 'radioset1', 'radioset2', ...

You can then loop over the results while $_POST['radioset'.$i] is available (start $i at zero, and increment it inside the while loop). If that value matches the current cat_letter from the database, then increment your 'score' counter.

Let me know if you need more explanation, its late and I'm tired, so probably aren't explaining it well.

Actually, you can read up on it some here: http://php.codeislogic.com/database-...-radio-buttons
bsboard is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-11-2007, 04:13 AM   #3 (permalink)
Junior Member
 
white10's Avatar
 
Join Date: 10-05-06
Posts: 23
iTrader: 0 / 0%
Latest Blog:
None

white10 is liked by many
Thanks bsboard,
that work quite well, thanks for the help.. I figured out another way to do it but the code was way to long, yours is much shorter...
white10 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
next buttons ball420 Coding Forum 8 03-21-2007 12:13 PM
Web Page Buttons Brian M Graphic Design Forum 8 03-07-2007 04:26 AM
IE Buttons Calisonder Coding Forum 2 12-02-2005 01:42 PM
Drop Downs or Radio buttons RingingPHoneML Web Usability 4 06-16-2004 04:36 PM
Buttons ... Atom Graphic Design Forum 7 12-01-2003 04:24 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 03:09 PM.
© Copyright 2008 V7 Inc