I have created a simple search function which looks through a few fields based on whatever the user inputs. It then returns the results as hyperlinks just displaying the titles of the schools. I am trying to then allow the user to view the rest of the information on a separate page. I have given each record a unique ID but I'm struggling to work out how to call it on the desired page. Here is the code i have used for the search results page search.php
<?php
require_once 'connection.inc.php';
if(isset($_GET['keywords'])){
$keywords = $db->escape_string($_GET['keywords']);
$query = $db->query("
SELECT school, address_town
FROM School
WHERE school LIKE '%{$keywords}%'
OR address_town LIKE '%{$keywords}%'
");
?>
<div class ="result-count">
Found <?php echo $query->num_rows; ?> results
<br>
<?php
if ($query->num_rows == 0)
echo "Sory there were no results matching your search" ;{
}
?>
</div>
<?php
if($query->num_rows){
while($r = $query->fetch_object()){
?>
<div class ="result">
<a href='school.php?id=".$row['id']."'><?php echo $r-> school; ?></a>
</div>
<?php
}
}
Here is the code for the page where i would like to display all of the information that i have on that particular record. This page is school.php
<?php
include ('connection.inc.php');
connect();
$sql = "SELECT * FROM School WHERE id = ".$_GET['id'];
$result = mysql_query($sql);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>School Details</title>
</head>
<body>
<?php
while ($record = mysql_fetch_object($result))
{
?>
<div class="post">
<p class="school"><? echo $record->school; ?></p>
<p class="address_1"><? echo $record->address_1; ?></p>
<p class="address_town"><? echo $record->address_town; ?></p>
<p class="postcode"><? echo $record->postcode; ?></p>
<p class="website"><? echo $record->website; ?></p>
<p class="phone"><? echo $record->phone; ?></p>
<p class="council"><? echo $record->council; ?></p>
<p class="pupils"><? echo $record->pupils; ?></p>
<p class="age_range"><? echo $record->age_range; ?></p>
<p class="gender"><? echo $record->gender; ?></p>
<p class="school_type"><? echo $record->school_type; ?></p>
<p class="ofsted_rating"><? echo $record->ofsted_rating; ?></p>
<p class="ofsted_report"><? echo $record->ofsted_report; ?></p>
<p class="gcse_percentage"><? echo $record->gcse_percentage; ?></p>
<p class="points_score"><? echo $record->points_score; ?></p>
<p class="pupil_teacher_ratio"><? echo $record->pupil_teacher_ratio; ?></p>
<p class="absence_percentage"><? echo $record->absence_percentage; ?></p>
<p class="language_not_english"><? echo $record->language_not_english; ?></p>
<p class="free_school_meals"><? echo $record->free_school_meals; ?></p>
<p class="happiness"><? echo $record->happiness; ?></p>
<p class="ofsted_parent_review"><? echo $record->ofsted_parent_review; ?></p>
<p class="events"><? echo $record->events; ?></p>
<p class="school_description"><? echo $record->school_description; ?></p>
<?php
}
mysql_free_result($result);
mysql_close();
?>
</body>
</html>
If anybody could help that would be great, Im quite new to this and picking it up as I go.
Thanks