我如何使用PHP来允许用户查看其他用户配置文件

时间:2013-09-12 01:37:48

标签: php

我正在创建一个社交网络,当我第一次创建我的搜索栏以查找名称时我做得很好但是当我点击任何名称时,我会看到谁登录这里的个人资料是我的搜索的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

0 个答案:

没有答案