Sakshi Sharma
Sakshi Sharma

Reputation: 1472

pass array result to a class

hello friends i am trying to get a list of user id and want to pass the whole result to a class which is called from a other file . my code is

$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);

here the class which i have called is and want pass all the values of uid from it . but only one username is being passed . can any one help me out in this .

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

browse list function --

<?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(); 
?>

Upvotes: 0

Views: 135

Answers (1)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57690

First you need to initialize the $like_users variable.

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

In your Browse class "select * from users_profile where uid='$users'" will be evaluated to "select * from users_profile where uid='Array'" as $users is an array of user id. You need to build the sql like,

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

Now this query should work unless there are some logical errors.

Upvotes: 1

Related Questions