Reputation: 1
I've got a working php script that returns a table from a mysql database just fine. I'm working on a somewhat complicated html page that displays information from different sources all over the page. How do I go about using a div in my existing html to get this returned table to show up?
The working php
<?php
$con=mysqli_connect("localhost","mylogin","mypass","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM mysqltable");
echo "<table border='1'>
<tr>
<th>Category</th>
<th>Contents</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['contents'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I tried a simple standalone html below but it returns blank and I can't find much else on the topic. Any help is appreciated! (I'm also looking to learn how to make this section update itself continually or every so many seconds in the future as multiple contributors will be submitting to it.)
Tried and failed html
<html>
<body>
<div style="width: 330px; height: 130px; overflow: auto;">
<?php include 'workingphp.php'; ?>
</div>
</body>
</html>
Again, very much appreciate assistance.
Upvotes: 0
Views: 4430
Reputation: 1176
You can use jQuery Ajax to get content from other page
$("#div1").load("workingphp.php");
Where #div1 would be id for your div
<div style="width: 330px; height: 130px; overflow: auto; id="div1">
Also the include tag , should work fine. If you include them in php page
<?php include 'workingphp.php'; ?>
Upvotes: 1
Reputation: 302
your html file must be a php file, that mean change page.html into page.php
Upvotes: 2