When entering query to the search bar and finding more than one match the checkbox reveals more details for the first match only.
<?php
$query = $_POST['query'];
$min_lenght = 3;
if(isset($_POST['query']) &&(strlen($_POST['query']) >= $min_length)){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM sales_properties WHERE
(`Address1` LIKE '%".$query."%') OR (`Address2` LIKE '%".$query."%')
OR (`Address3` LIKE '%".$query."%') OR (`postcode` LIKE
'%".$query."%')") or die (mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo
"<br>".$results['Address1']." ".$results['Address2']." ".$results['Address3']."<input type='checkbox' id='myCheck' onclick='myFunction()'>".
"<p id='text' style='display:none'>"."Price: £".$results['price']." | "."Bedrooms: ".$results['bedrooms'].
" | Bathrooms: ".$results['bathrooms']." | Lounges: ".$results['receptions']."<br> Tenure: ".$results['sales_tenure']."</p>".
"<br>";
}
}
else{
echo "No results";
}
}
else{
echo "<br>"."Try searching by name or surname, minimum of ".$min_length . " characters are required. "."<br>";
}
?> < script >
function myFunction() {
var checkBox = document.getElementById('myCheck');
var text = document.getElementById('text');
if (checkBox.checked == true) {
text.style.display = 'block';
} else {
text.style.display = 'none';
}
} < /script>`enter code here`
The first checkbox works as intended, but the next ones after that is not working at all. Should I use "foreach".