I have created dynamic buttons in php but i want to fetch value from databse and set it to the buttons but it didnt fetch and set.give any solution for this. In databse there is 5 values and that value i want to set to the buttons
following code i have tried.
<?php
function dash()
{
include 'config.php';
$sql = "SELECT roomno FROM roombook";
if($result = mysqli_query($db, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$str='';
$roomno=array($row['roomno']) ;
// $aa=array($roomno);
//echo "$arr";
while(list($k,$v)=each($roomno)) {
$str.='<input type="submit" name="btn_'.$k.'" value="'.$v.'" id="btn_'.$k.'"/>';
}
return $str;
}
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($db);
//$btn=array(1=>'hjck',2=>'102',3=>'104');
}
?>
<!Doctype html>
<html>
<body>
<div id="bpanel" >
<?php echo dash();?>
</div>
</body>
</html>