I used this existing question to help me out: HTML - Change\Update page contents without refreshing\reloading the page
The template-comparison.php file fetches the code from the header.php code but the actual "fetch code" isn't shown. Otherwise, the template page would have no header. The templatecode.php file is the code used to fetch and display the database data.
My code:
template-comparison.php
<a href="#" onClick="prescand('1')" >link text</a>
<a href="#" onClick="prescand('2')" >link text 2</a>
<div id='myStyle'>
</div>
templatecode.php
<?php
$servername = "localhost";
$username = "hidden for security purposes";
$password = "hidden for security purposes";
$dbname = "hidden for security purposes";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ID = $_GET['ID'];
$results = mysql_query("SELECT * FROM PresidentialCandidate WHERE ID='$ID'");
if( mysql_num_rows($results) > 0 )
{
$row = mysql_fetch_array( $results );
echo $row['ID'];
}
?>
header.php
<script type="text/javascript">
function prescand(ID) {
$('#myStyle').load('templatecode.php?id=' + ID);
}
</script>
What happens:
I click the link. Nothing happens. It just acts like an anchor that pushes me to the top of the page.
Any ideas? What I want is to have ALL of the data for the link clicked (eg: ID 1...link text) to be displayed in the div. If I click, ID 2 (link text 2), the data for that ID is shown.