使用php查找和显示所有用户[关闭]

I am trying to display all user who have same id with the user id

Suppose pim za is user and her id = 1 , I want to display who all have oid= 1.

I am facing problem in displaying them. I want it to display all user and end when there is no user left.

I am using following way:

$CheckQuery = mysql_query("SELECT * FROM tblfduser WHERE id='$user->id'");   

The display should be as follow:

Try

$CheckQuery = mysql_query("SELECT * FROM tbluser WHERE id='".$user->id."'"); 

now after query you can get associative array as below.

while($row = mysql_fetch_assoc($CheckQuery))
{
    echo $row['uname']."<br/>";
}

Please do not use mysql_* as its deprecated.

be careful with sql injection

SELECT  a.ID, a.Fname, a.Lname, a.OID,
        b.ID bID, 
        b.Fname oFNAME, 
        b.Lname oLNAME 
FROM    users a
        INNER JOIN users b
            ON a.id = b.oid
ORDER BY a.ID

I would do like this: (I would believe this is right way using PDO)

Your YourClass; Your Function:

public static function getByOid( $oid ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT * FROM users WHERE oid = :oid";
$st = $conn->prepare( $sql );
$st->bindValue( ":oid", $oid, PDO::PARAM_INT );
$st->execute();
$row = $st->fetch();
$conn = null;
if ( $row ) return new YourClass( $row );
}

and Calling class::function:

$results['oid'] = YourClass::getByOid( (int)$_GET["oid"] );

and on your page, fetching results:

using "foreach"