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();
?>
$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
}
}
?>
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
}
?>
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
Post a Comment