0

我正在创建一个社交网络,当我第一次为名称创建搜索栏时,我做得很好,但是当我单击任何名称时,它会将我带到曾经登录过的人的个人资料这里是我的搜索栏的 php 代码

?php
include 'func.inc.php';
if (isset($_POST['full_name'])) {
  $first_names = mysql_real_escape_string(htmlentities($_POST['full_name']));

  $errors = array();

if (empty($first_names)) {
   $errors[] = 'Please enter a search term';
} else if (strlen($first_names)<3) {
   $errors[] = 'Your search term must be three or more charecters';
} else if (search_results($first_names) === false) {
   $errors[] = 'Your search for '.$first_names.' returned no results';
}

?>  
<?php
if (empty($errors)) {
 $results = search_results($first_names);
 $results_num = count($results);

 echo '<div align="center"> <p>Your search for <strong>', $first_names, '</strong> returned <strong>', $results_num, '</strong> results</p> </div>';

 foreach($results as $result) {
    echo '<h3> <strong> <div align="center"> <a href="profile job.php?user_id=', $result['user_id'],'"> ', $result['first_name'],' ', $result['last_name'], '</a><br> ', $result['address'],'</div> </strong> </h3>';
  }
 }
}
?>  
here is func.inc.php
<?php
include 'db.inc.php'; 

function search_results($first_names) { 
 $returned_results = array();
 $where = "";

$first_names = preg_split('/[\s]+/', $first_names);
$total_first_names = count($first_names);

foreach($first_names as $key=>$first_name) {
  $where .= "`full_name` LIKE '%$first_name%'";
  if ($first_name != ($total_first_names - 1)) {
  $where .= " AND ";
  }
 }

$results = "SELECT `user_id`, `first_name`, `last_name` FROM `users` WHERE $where";
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;

if ($results_num === 0) {
  return false;
 } else {

     while ($results_row = mysql_fetch_assoc($results)) {
      $returned_results[] = array(
       'first_name' => $results_row['first_name'],
       'last_name' => $results_row['last_name'],
       'user_id' => $results_row['user_id']\
      ); 
     }

     return $returned_results;
   }

}   

?>

请详细解释一下,如果有任何问题,请通过 philipnagel511@gmail.com 向我发送电子邮件

4

0 回答 0