Hi all,
You can forget my previous CSS Table result issue, I'm trying something cleaner now, but its only returning one result.
Here's the php
I believe the issue is around this particular area:
I commented out the "echo <p><h3>" line above. Actually, if I leave that in, it works, but doesn't look pretty...
Can anyone see what I might have broken?
Ta![Smile :) :)](/styles/default/xenforo/vbSmilies/Normal/smile.gif)
You can forget my previous CSS Table result issue, I'm trying something cleaner now, but its only returning one result.
Here's the php
PHP:
<?php
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM contacts WHERE (`name` LIKE '%".$query."%') OR (`email` LIKE '%".$query."%') OR (`telephone` LIKE '%".$query."%') OR (`address` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the
$id = stripslashes($results['id']);
$name = stripslashes($results['name']);
$telephone = stripslashes($results['telephone']);
$email = stripslashes($results['email']);
$address = stripslashes($results['address']);
//echo "<p><h3>".$results['name']."</h3>".$results['address']."</p>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
<p><strong>Name:</strong><?php echo $name; ?></p>
<p><strong>Telephone:</strong><?php echo $telephone; ?></p>
<p><strong>Email:</strong><?php echo $email; ?></p>
<p><strong>Address:</strong><?php echo $address; ?></p>
I believe the issue is around this particular area:
PHP:
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the
$id = stripslashes($results['id']);
$name = stripslashes($results['name']);
$telephone = stripslashes($results['telephone']);
$email = stripslashes($results['email']);
$address = stripslashes($results['address']);
//echo "<p><h3>".$results['name']."</h3>".$results['address']."</p>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
I commented out the "echo <p><h3>" line above. Actually, if I leave that in, it works, but doesn't look pretty...
Can anyone see what I might have broken?
Ta
![Smile :) :)](/styles/default/xenforo/vbSmilies/Normal/smile.gif)