将数组结果传递给一个类

时间:2012-02-04 08:40:08

标签: php mysql arrays class

你好朋友我正在尝试获取用户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(); 
?>

1 个答案:

答案 0 :(得分: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)");

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