I have a “print.php” script that basically fetches data from MySQL and creates a tiny pretty HTML table.
echo "
<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"10%\">
<tr bgcolor=\"#666666\">
<td colspan=\"2\" align=\"center\"><b><font color=\"#FFFFFF\">" . $table[0] . "</font></td>
</tr>
<tr>
<td>Name</td>
<td>Score</td>
</tr>";
echo "<tr";
if ($i % 2 == 0)
echo " bgcolor=\"#CCCCCC\"";
echo ">
<td>" . $col['player'] . "</td>
<td>" . $col['score'] . "</td>
</tr>";
I want this table to appear in my index.html, But its in a separate php script.
I want to keep the php script separate from the HTML because the script is not only a tad large, but it has my SQL information in it to which I don’t want in the plain HTML.
Is there a way to fetch this echo in my php script from my html page?
Option 1:
Use an iframe. Works even if JavaScript is turned off.
Option 2: Use AJAX (with jQuery).
Download jQuery here.
Include it in your
index.html, preferably in yourheadtag.Add this code where you want
print.phpto be included.Option 3: Go the PHP route. May break other code since you need to rename the index file.
Rename your
index.htmltoindex.phpand use this code: