In this video tutorial you will know to Display Mysql Data in a Select List of Bootstrap framework With php pdo.
Bootstrap link : http://getbootstrap.com/
.php mysql pdo connection
index.php file
<?Php
$dbhost = 'localhost';
$dbname = 'selectlist';
$dbuser = 'root';
$dbpass = '';
try{- $dbcon = new PDO("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $ex){
die($ex->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->- <title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<h1>Dynamic Select List in php mysql!</h1>
<div class="col-md-4">
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1">
<?php
$sqlquery = $dbcon->prepare('SELECT * FROM selectlist ORDER BY id DESC');- $sqlquery->execute();
while($row=$sqlquery->fetch(PDO::FETCH_ASSOC))
{
extract($row)
?>- <option>
<?php
echo $row['title'];
?>
</option>
<?php
}
?>
</select>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>- </html>
Your website is very beautiful or Articles. I love it thank you for sharing for everyone. Vue Js Php Tutorial
ReplyDelete