PDA

View Full Version : مبتدی: شمردن تعداد چک باکس های انتخابی



sina12345678910
یک شنبه 22 آذر 1394, 22:13 عصر
سلاااام خسته نباشید!!!
میخوام یه برنامه بنویسمم که 10 تا سوال از کاربر بپرسم و هر سوال دوتا چک باکس داره بله و خیر
حالا میخوام بعد از زدن submit تعداد بله ها و خیر هایی که کاربر وارد کرده را بشمرم
اگه کمکممممممم کنین ممنون میشم
:تشویق::تشویق::تشویق::تشویق:: شویق::تشویق::تشویق::تشویق::ت ویق::تشویق:

مهرداد سیف زاده
یک شنبه 22 آذر 1394, 23:44 عصر
این کد پویا هستش یعنی میشه سوال خودکار با دیتابیس درست کرد و بصورت خودکار فرم رو بسازه و array تولید کنه و بشماره و تحویل بگیره از کاربر
و تا فایل هست یکی index.php که فرم رو لود میکنه. و دیگری form_handle.php که داده‌های فرم رو میگیره و شمارش میکنه.


<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
</head>
<body>
<form action="form_handle.php" method="post" accept-charset="utf-8">
<table class="pure-table pure-table-horizontal">
<thead>
<tr>
<th>question</th>
<th>answer</th>
</tr>
</thead>
<tbody>
<tr>
<td>iran best country?</td>
<td>
<label><input type="radio" name="country_ok" value="1" placeholder=""> ok</label>
<label><input type="radio" name="country_no" value="1" placeholder=""> no</label>
</td>
</tr>
<tr>
<td>iranian developers best developer?</td>
<td>
<label><input type="radio" name="developer_ok" value="1" placeholder=""> ok</label>
<label><input type="radio" name="developer_no" value="1" placeholder=""> no</label>
</td>
</tr>
<tr><td colspan="2"><button type="submit">Send</button></td></tr>
</tbody>
</table>
</form>
</body>
</html>


form_handle.php


<?php
$questions = array(
'country'=>'',
'developer'=>''
);


if(isset($_POST))
{
foreach ($_POST as $k => $v) {
$sel = explode('_', $k);


if(array_key_exists($sel[0], $questions))
{
$questions[$sel[0]]=$sel[1];
}
}
}


?>


<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<title></title>
</head>
<body>
<table class="pure-table">
<caption>user answered </caption>
<thead>
<tr>
<th>question</th>
<th>answer</th>
</tr>
</thead>
<tbody>
<?php
foreach ($questions as $kq => $vq) {
?>
<tr><td><?=$kq?></td><td><?=$vq?></td></tr>
<?php
}
?>

</tbody>
</table>


</body>
</html>