fetch data fron mysql different table connected using foreing key based on id



php code

<!DOCTYPE html>
<html>
<head>
<title>Read Data From Database Using PHP - Demo Preview</title>
<meta content="noindex, nofollow" name="robots">
<style>
@import "http://fonts.googleapis.com/css?family=Droid+Serif";
/* Above line is to import google font style */
.maindiv {
margin:0 auto;
width:980px;
height:500px;
background:#fff;
padding-top:20px;
font-size:14px;
font-family:'Droid Serif',serif
}
.title {
width:100%;
height:70px;
text-shadow:2px 2px 2px #cfcfcf;
font-size:16px;
text-align:center;
font-family:'Droid Serif',serif
}
.divA {
width:70%;
float:left;
margin-top:30px
}
.form {
width:400px;
float:left;
background-color:#fff;
font-family:'Droid Serif',serif;
padding-left:30px
}
.divB {
width:100%;
height:100%;
background-color:#fff;
border:dashed 1px #999
}
.divD {
width:200px;
height:480px;
padding:0 20px;
float:left;
background-color:#f0f8ff;
border-right:dashed 1px #999
}
p {
text-align:center;
font-weight:700;
color:#5678C0;
font-size:18px;
text-shadow:2px 2px 2px #cfcfcf
}
.form h2 {
text-align:center;
text-shadow:2px 2px 2px #cfcfcf
}
a {
text-decoration:none;
font-size:16px;
margin:2px 0 0 30px;
padding:3px;
color:#1F8DD6
}
a:hover {
text-shadow:2px 2px 2px #cfcfcf;
font-size:18px
}
.clear {
clear:both
}
span {
font-weight:700
}
</style>
</head>
<body>
<div class="maindiv">
<div class="divA">
<div class="title">
<h2>Read Data Using PHP</h2>
</div>
<div class="divB">
<div class="divD">
<p>Click On Menu</p>
<?php
$servername="localhost";
$username="root";
$password="";
$database="okmam";

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


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



//$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
//$db = mysql_select_db("okmam", $connection); // Selecting Database
//MySQL Query to read data
$query = mysqli_query($conn,"select * from dress");
while ($row = mysqli_fetch_array($query)) {
echo "<b><a href=\"fromdatabase5.php?id={$row['OMDR_ID']}\">{$row['OMDR_NAME']}</a></b>";
echo "<br />";
}
?>
</div>
<div class="form"><h2>---FRONT---</h2></div>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query1 = mysqli_query($conn, "select * from front where OMDR_ID=$id");
while ($row1 = mysqli_fetch_array($query1)) {
?>
<div class='form'>
<!--<h2>---sleeve---</h2>-->
<!-- Displaying Data Read From Database -->
<!-- <span>FRONT ID:</span> <?php echo $row1['OMFR_ID']; ?><BR/>-->
<span>FRONT NAME:</span> <?php echo $row1['OMFR_NAME']; ?><BR/>
<!-- <span>DRESS ID:</span> <?php echo $row1['OMDR_ID']; ?><BR/>-->
</div>

<?php
}
}
?>
<div class="form"><h2>---BACK---</h2></div>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query2 = mysqli_query($conn, "select * from back where OMDR_ID=$id");
while ($row2 = mysqli_fetch_array($query2)) {
?>
<div class="form">

<!-- Displaying Data Read From Database -->
<!-- <span>BACK ID:</span> <?php echo $row2['OMBA_ID']; ?><BR/>-->
<span>BACK NAME:</span> <?php echo $row2['OMBA_NAME']; ?><BR/>
<!-- <span>DRESS ID:</span> <?php echo $row2['OMDR_ID']; ?><BR/>-->
</div>
<?php
}
}
?>

<div class="form"><h2>---SLEEVE---</h2></div>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query3 = mysqli_query($conn, "select * from sleeve where OMDR_ID=$id");
while ($row3 = mysqli_fetch_array($query3)) {
?>
<div class="form">
<!--<h2>---sleeve---</h2>-->
<!-- Displaying Data Read From Database -->
<!-- <span>SLEEVE ID:</span> <?php echo $row3['OMSL_ID']; ?><BR/>-->
<span>SLEEVE NAME:</span> <?php echo $row3['OMSL_NAME']; ?><BR/>
<!-- <span>DRESS ID:</span> <?php echo $row3['OMDR_ID']; ?><BR/>-->
</div>
<?php
}
}
?>
<div class="form"><h2>---ADDONS---</h2></div>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query4 = mysqli_query($conn, "select * from addons where OMDR_ID=$id");
while ($row4 = mysqli_fetch_array($query4)) {
?>
<div class="form">
<!--<h2>---addons---</h2>-->
<!-- Displaying Data Read From Database -->
<!-- <span>ADDONS ID:</span> <?php echo $row4['OMAD_ID']; ?><BR/>-->
<span>ADDONS NAME:</span> <?php echo $row4['OMAD_NAME']; ?><BR/>
<!-- <span>DRESS ID:</span> <?php echo $row4['OMDR_ID']; ?><BR/>-->
</div>
<?php
}
}
?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>


</div>
<?php
mysqli_close($conn); // Closing Connection with Server
?>
</body>
</html>




Comments

Popular posts from this blog

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

PHP Ajax Login Validation Tutorial

Insert CheckBox and Radio button Data in MySQL Database Using PHP