This is my database table. I'm currently displaying option1-10 as text but I want to display it as an input type for each option depending if its answer_type column is radiobutton or checkbox. It also shouldn't display when the value of option1-10 is null. Also how do i group it into one like for example if it's a radiobutton, i should only be able to choose one?
Here's my code of displaying the text
ajax
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","hay.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
</html>
<form>
<select name="users" onchange="showUser(this.value)">
<option>-None Selected-</option>
<?php
$con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect");
$query=mysqli_query($con, "SELECT * FROM question");
while($row=mysqli_fetch_array($query)) {
?>
<option value="<?php echo $row["question_id"]; ?>"><?php echo $row["questiontitle"]; ?></option>
<?php
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
php code
<?php
$con = mysqli_connect('localhost','root','','imetrics') or die ("Cannot connect to database");
if(!$con){
echo ('Could not connect: ' . mysqli_error($con));
}
$id= isset($_GET["q"])?$_GET["q"]:"";
$query = mysqli_query($con, "SELECT * FROM question WHERE question_id = '".$id."'");
while($row = mysqli_fetch_array($query)) {
echo $row['Option_1'] . "<br>";
echo $row['Option_2'] . "<br>";
echo $row['Option_3'] . "<br>";
echo $row['Option_4'] . "<br>";
echo $row['Option_5'] . "<br>";
echo $row['Option_6'] . "<br>";
echo $row['Option_7'] . "<br>";
echo $row['Option_8'] . "<br>";
echo $row['Option_9'] . "<br>";
echo $row['Option_10'] . "<br>";
}
?>
What's the right condition for my problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…