abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/11/2020

How to create automatic result showing page with students name on HTML?

 in this blog shows how to get auto value into html


suppose we want maintain student data


step 1) create database it may mysql or sqlite

<?php

$servername = "localhost";

$username = "username";

$password = "password";


// Create connection

$conn = new mysqli($servername, $username, $password);

// Check connection

if ($conn->connect_error) {

  die("Connection failed: " . $conn->connect_error);

}


// Create database

$sql = "CREATE DATABASE myDB";

if ($conn->query($sql) === TRUE) {

  echo "Database created";

} else {

  echo "Error creating database: " . $conn->error;

}


$conn->close();

?>


step 2) write html to get value from above created database


<html>

<body>

<div>

<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";


// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

  die("Connection failed: " . $conn->connect_error);

}


$sql = "SELECT id, firstname, lastname FROM student";

$result = $conn->query($sql);

if ($result->num_rows > 0) { // output data of each row

  

  while($row = $result->fetch_assoc()) {

echo "<p>id: " . $row["id"]. "</p> - <p>Name: " . $row["firstname"]. "</p> " . $row["lastname"]. "<br>";

  }

} else {

  echo "0 results";

}

$conn->close();

?>

</div>

</body>

</html>

from above code we get data from mysql table which shows student first name and last name, 

important note - always add id & set it to primary key, into table because it is unique value in case referenece required id value is good to compare. 


please comment your query,remarks.

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...