php mysql retrieve and display data based on id or name

db1.php

 <?php
$servername="localhost";
$username="root";
$password="";
$database="tuts_rest";

//create connection$
$conn=new mysqli($servername, $username, $password, $database);


//check connection
if ($conn->connect_error)
{
    die("connection failed: ".$conn->connect_error);
}
    session_start();
?>

based on id

 <?php
include_once('includes/db1.php');

//$query = mysqli_query($conn,"select * from users");
//while ($row = mysqli_fetch_array($query)) {
//echo "<tr><td><a href=details.php?id=$row[ID]>$row[name]</a></td><td>$row[email]</td></tr>";
//echo "<br />";
//}

if (isset($_GET['ID'])) {
$name = $_GET['ID'];
$query1 = mysqli_query($conn, "select * from users where ID=$id");
while ($row1 = mysqli_fetch_array($query1)) {
?>
<td><?php echo $row1['name']; ?></td>
<?php
}
}

?>

based on name

 <?php
include_once('includes/db1.php');

//$query = mysqli_query($conn,"select * from users");
//while ($row = mysqli_fetch_array($query)) {
//echo "<tr><td><a href=details.php?id=$row[ID]>$row[name]</a></td><td>$row[email]</td></tr>";
//echo "<br />";
//}


$name = $_GET['name'];
$query1 = mysqli_query($conn, "select * from users where name='$name'");
while ($row1 = mysqli_fetch_array($query1) ) {
?>
<td><?php echo $row1['name']; ?></td>
<?php
}


?>

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Hyperledger Development with in 10 days — Day 6

Insert CheckBox and Radio button Data in MySQL Database Using PHP