传递数组结果到一个类

传递数组结果到一个类

问题描述:

你好朋友我想获得用户id的列表,并希望将整个结果传递给从其他文件调用的类。我的代码是传递数组结果到一个类

$host = "localhost"; 
$user = "root"; 
$pwd = ""; 
$conn = mysql_connect($host, $user, $pwd) or die("database connection failed"); 
$connection = mysql_select_db("4ever1", $conn); 
include_once ("../browse/browse.php"); 
echo $object_id = $_GET['lid']; 
echo $id = $_GET['id']; 
echo $type = $_GET['type']; 
$like_no = mysql_query("SELECT * FROM likes where like_id = '$object_id' AND  type_id='$type'"); 
echo "SELECT * FROM likes where like_id = '$object_id' AND type_id='$type'"; 
while ($row = mysql_fetch_array($like_no)) { 
    $like_users[] = $row['like_uid']; 
} 
$browse_result->browse_list($id, $like_users, $type); 

这里我调用的类是并且想要从它传递所有的uid值。但只有一个用户名正在传递。任何人都可以帮助我解决这个问题。

  $browse_result->browse_list($id,$like_users,$type); 

浏览列表功能 -

<?php 
class browse { 
    function Browse_List($id, $users, $type) { 
     include ("../../includes/connection.php"); 
     $sql1 = mysql_query("select * from users_profile where uid='$users'"); 
     while ($row1 = mysql_fetch_array($sql1)) { 
      $profile_fname = $row1['fname']; 
      $profile_lname = $row1['lname']; 
      $profile_pic = $row1['profile_pic']; 
      $profile_country = $row1['country']; 
      $profile_relationship_status = $row1['relationship_status']; 
      ?> 
      <li><a href="#"> 
      <img class="likeu_image" src="../../<?php echo $profile_pic; ?>" /> 
      <div class="like_menu"><span class="like_uname"> 
      <?php echo $profile_fname . " " . $profile_lname; ?></span></div> 
      <div class="like_details"><span class="like_content"> 
      <?php echo $profile_relationship_status; ?></br> 
      <?php echo $profile_country; ?></span></div> 
      <?php $vp_result->addfriends($id, $users); ?> 
      </a></li><?php 
     } 
    } 
} 
$browse_result = new browse(); 
?> 
+0

你可以把'browse_list'功能 – mgraph 2012-02-04 08:48:25

+0

是m发布是2mins ... – 2012-02-04 08:50:36

首先,你需要初始化$like_users变量。

$like_users = array(); 
while ($row = mysql_fetch_array($like_no)) { 
    $like_users[] = $row['like_uid']; 
} 

在你Browse"select * from users_profile where uid='$users'"类将被评估,以作为"select * from users_profile where uid='Array'"$users用户ID的数组。你需要建立像这样的SQL,

$users_list = "'". implode("','", $users) ."'"; 
$sql1 = mysql_query("select * from users_profile where uid IN ($users_list)"); 

现在这个查询应该工作,除非有一些逻辑错误。

+0

感谢很多朋友,现在它的工作正常。 – 2012-02-04 09:13:49