I know there are other post conserning this but they dont seem to help me. When I run the varaible $results
through the function Mysql_num_rows()
it returns as an error saying its not a valid result. Also same for the mysql_fetch_array()
.
function results(){
if ($_POST['search'] != "") {
$search = mysql_real_escape_string($_POST['search']);
$search = filter_var($search, FILTER_SANITIZE_STRING);
//remove unwanted characters from number.
$search = ereg_replace("[^A-Za-z0-9]", "", $search);
$search = strtolower($search);
$search = preg_replace('/\s+/','',$search);
}
else{echo '<div class="noresults">No Results</div>'; die();}
//start query for search
$query = "SELECT * FROM members WHERE number = '$search' ORDER BY user_id ASC";
//run query
$results = mysql_query($query);
if(mysql_num_rows($results) == 0){
echo '<div class="noresults">No Results</div>';
}
while($row = mysql_fetch_array($results)){
echo '<div class="comments_about_wrapper">
<div class="comment_text_wrapper">
<div class="comment_text"><p style="float:left;">Number:</p><p style="float:right; padding-right:100px;">Location:</p>
</br>
<p style="float:left;">';
echo $row['number'];
echo'</p><p style="float:left; padding-left:108px;">';
echo $row['location'];
echo'</p>
</div>
</div>
<div class="comments_about_small_box_wrapper">
<div class="comments_about_picture">
<a href=""><img src="" width="45px" height="45px"></a>
</div>
</div>
</div>';
}
}
The table for members is
user_id email password number first_name last_name location
1 example1@gmail.com 1234 123 Bob Jones xxx
2 sample2@gmail.com abcd 456 John Smith YYY