2012-02-04 71 views
0

你好朋友我想獲得用戶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

回答

1

首先,你需要初始化$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