i am new to php & would like to call another php file on the same file in the div tag. on the home page i am calling the php file & have link on those files & want to open the result of that link below in the div tag. I want to dispaly the result of all the links in the div tag
Please Help !
Thanks in advance
ViewBdd.php
<html>
<body>
<table align="center" width="100%">
<tr>
<td>
<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"csdata");
$result = mysqli_query($con,"SELECT *
FROM `data`");
echo "<table border='1' cellpadding='5' cellspacing='2' style='border:black; ' align='center'>
<tr><th colspan='4'>(BDD-2015)</th></tr>
<tr>
<th id='td'>Customer Name</th>
<th id='td'>Rs. in Lakhs</th>
<th id='td'>Metric Ton</th>
<th id='td'>Percentage</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' id='td'><a href='sku.php?Customer_name=" . $row['Customer_name'] . "'>" . $row['Customer_name'] . "</a></td>";
echo "<td align='center' id='td'>" . round($row['Total'],2) . "</td>";
echo "<td align='center' id='td'>" . round($row['MT'],2) . "</td>";
echo "<td align='center' id='td'>" . round($row['Percentage'],2) . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?></td>
</tr>
</table>
</body>
</html>
sku.php
<html>
<body>
<table align="center" width="100%">
<tr>
<td>
<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"csdata");
$name=$_GET['Customer_name'];
$result = mysqli_query($con,"Select * from `data` ");
echo "<table border='1' cellpadding='5' cellspacing='2' style='border:black; ' align='center'>
<tr>
<th id='td'>Customer Name</th>
<th id='td'>Item Name</th>
<th id='td'>Rs. in Lakhs</th>
<th id='td'>Metric Ton</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' id='td'>" . $row['Customer_Name'] . "</td>";
echo "<td align='center' id='td'>" . $row['Item_Grouping'] . "</td>";
echo "<td align='center' id='td'>" . round($row['Amount'],2) . "</td>";
echo "<td align='center' id='td'>" . round($row['MT'],2) . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?></td>
</tr>
</table>
</body>
</html>
In order to call another PHP script without refreshing a page you have to use AJAX
As for your code:
Some changes to your code:
Instead of
use
<div class="sales"><a href="SalesBdd.php" class="get_result"></a></div>
Then add
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
to home.php
Then add to home.php script
$('.get_result').click(function (event)
{
event.preventDefault();
var url = $(this).attr('href');
$.get(url, function(data) {
$('.sales').html(data);
});
});
As a result then you press link, the resulting html (which is get from php page) will be placed instead of link into div.
HTML frames are used to solved your problem, whice is user to divide your browser window into multiple sections where each section can load a separate HTML document. A collection of frames in the browser window is known as a frameset. The window is divided into frames in a similar way the tables are organized: into rows and columns.
So you try to use Frame concept Instead writing more than one html tag within one page.
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,80%,10%">
<frame name="top" src="abc.html" />
<frame name="main" src="xyz.html" />
<frame name="bottom" src="abcd.html" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
The above example to create three horizontal frames.
If you want to create all the frames vertically, change the line as
<frameset cols="25%,50%,25%">