I created a faculty evaluation system a when I click the category 1 in the dropdown menu and add a question in textarea and submit it the first question I submit would not show in the questionnaire but when I add again it will show. If I add a question 2 and select category 1 the question I added will go to category 2.
here is my code.....
PHP
<?php
session_start();
require './config.php';
if (isset($_POST['save'])) {
$question = $_POST['question'];
$query = "INSERT INTO `question_list`(`question`) VALUES ('$question]')";
$query_run = mysqli_query($db, $query);
if ($query_run) {
$_SESSION['message'] = "Created Successfully";
header("Location: add_questionaire");
exit(0);
} else {
$_SESSION['message'] = "Not Created";
header("Location: add_questionaire");
exit(0);
}
}
?>
<label for="setting-input-2" class="form-label">Category</label>
<fieldset class="form-group">
<select name="category_id" class="form-select" id="basicSelect">
<option hidden>Please select here.....</option>
<?php
$query = "SELECT * FROM `category_list`";
$query_run = mysqli_query($db, $query);
if (mysqli_num_rows($query_run) > 0) {
foreach($query_run as $category) {
?>
<option value="<?= $category['id']; ?>">
<?= $category['category']; ?>
</option>
<?php
}
} else {
echo "<h5> No Record Found </h5>";
}
?>
</select>
</fieldset>
<div class="mb-3">
<label for="setting-input-3" class="form-label">Question Name</label>
<textarea class="txt" name="question" id="" cols="33" rows="10" placeholder="What question to add?"></textarea>
</div>
<button type="submit" name="save" class="btn app-btn-primary">Save</button>
<fieldset class="border border-info p-2 w-100">
<legend class="w-auto">Rating</legend>
<p>5 = Strongly Agree, 4 = Agree, 3 = Uncertain, 2 = Disagree, 1 = Strongly Disagree</p>
</fieldset><br>
<?php
$q_arr = array();
$category = $db->query("SELECT * FROM category_list order by abs(order_by) asc ");
while($crow = $category->fetch_assoc()):
?>
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell"><b>
<?php echo $crow['category'] ?>
</th>
<th class="cell">5</th>
<th class="cell">4</th>
<th class="cell">3</th>
<th class="cell">2</th>
<th class="cell">1</th>
</tr>
</thead>
<tbody>
<?php
$question = $db->query("SELECT * FROM `question_list` where id = {$crow['id']} order by abs(order_by) asc ");
while($row=$question->fetch_assoc()):
$q_arr[$row['id']] = $row;
?>
<tr>
<td class="cell">
<?php echo $row['question'] ?>
<input type="hidden" name="qid[]" value="<?php echo $row['id'] ?>">
</td>
<?php for($c=1;$c<5;$c++): ?>
<td>
<input type="radio" name="qid[<?php echo $row['id'] ?>][]" id="qradio<?php echo $row['id'].'_'.$c ?>">
<label for="qradio<?php echo $row['id'].'_'.$c ?>"></label>
</td>
<?php endfor; ?>
</tr>
</tbody>
</table>
<?php endwhile; ?>
</tbody>
<?php endwhile; ?>
</table>
I'm expecting that when I choose category 1 and add a question in the textarea the question will show only in category 1. Please help me thank you
source https://stackoverflow.com/questions/77595443/how-can-i-add-5-questions-in-category-1-only
No comments:
Post a Comment