How to show fetch data in radio button using php


In this topic i am going to show you how to fetch data and show in a radio button.

Here we using two file for fetch data.

  1. database.php(For connect to database)
  2. index.php(Fetch data from database)

database.php

<?php
$servername='localhost';
$username='root';
$password='';
$dbname = "crud";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect My Sql:' .mysql_error());
}
?>

index.php

<!DOCTYPE html>
<html>
<head>
<title> Retrive data</title>
</head>

<body>
<h2>City Name</h2>
<?php
$i=0;
while($db_row = mysqli_fetch_array($result)) {
?>
<input type="radio" ><?php echo $db_row["city_name"]; ?><br>
<?php
$i++;
}
?>
</body>
</html>

Related Topic

Fetch data show in select box

Fetch data show in checkbox

Fetch data show in radio button

Fetch data show in text box