THat's difficult to follow. Could you explain that again?
1. you get data from DB based on what a form sends - OK
2. select value from combobox - ok - but what value are you talking about?
3. you want DB data to be the value of the radiobutton. What radio button??
diafol
Keep Smiling
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57
Question Answered as of 1 Year Ago by
diafol OK, that's relatively easy. Mind you, you could use 'false ajax' (my terminology) if you only have a handful of data items in the whole unfiltered dataset. That's when on page load, you get all the records from the SELECT * from type_tb type query and place the data into a js array. When you then select from the dropdown, it runs a js script to get the 'a' array items or the 'c' array items.
Just a thought. It saves going to the server and making DB server calls every time somebody selects something from the dropdown.
The down side of this is that any changes to the DB in the meantime will not be displayed on dropdown select. If your data is not going to be updated much, this should not be a great issue.
ANy use?
diafol
Keep Smiling
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57
As I posted my comment before it was solved (simultaneous post with your last one), I thought I should include my idea:
$listarray[] = 'Choose a letter...';
$r = mysql_query("SELECT SUBSTRING(`words`,1,1) AS letter, GROUP_CONCAT(`words`) AS `output` FROM table GROUP BY letter");
while($d=mysql_fetch_assoc($r)){
$x = explode(',',$d['output']);
sort($x);
$t[$d['letter']] = $x;
$listarray[] = $d['letter'];
}
$myarray = json_encode($t);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
var x = <?php echo $myarray;?>;
function showMe(){
var i = me.value;
var str = '';
if(x[i].length > 0){
for(z = 0;z < x[i].length; z++){
(z === 0) ? chk = ' checked="checked"' : chk = "";
str = str + '<input id="' + x[i][z] + '" type="radio" name="help" ' + chk + ' /> <label for="' + x[i][z] + '">' + x[i][z] + '</label>';
}
}
document.getElementById('showradios').innerHTML = str;
}
</script>
</head>
<body>
<form>
<select id="me" onchange="showMe();">
<?php
foreach($listarray as $item){
echo "<option value=\"$item\">$item</option>";
}
?>
</select>
<div id="showradios">
</div>
...
</form>
</body>
</html>
Somebody may find it useful or may even point out how to improve it.
diafol
Keep Smiling
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57