i have the following code

<?php
$id = $_SESSION["user_session"];
$get = mysql_query("SELECT * FROM table WHERE id='$id'");
$total_found = mysql_num_rows($get);
if($total_found==0){
	my code goes here
		}else{
			while($g = mysql_fetch_array($get)){
			$id_2 = $g["id"];			
			$query = mysql_query("SELECT * FROM table WHERE id != '$id' AND id!='$id_2'");
			while($z = mysql_fetch_array($query)){
				mycode goes here
			}
		}

?>

but it is not working.........!! please let me know..........how can i implent double loop............becuse the above code is fetching only on id from first loop...........!! how can i do that.........!!

Shishtawitch,

The code looks like it should work, however. two things .....

1. At the line $id_2 = $g["id"]; , surely $id_2 must be equal to $id because it comes from a row resulting from a query which returns rows where id=='$id' . If I'm right, then the second query doesn't need AND id!='$id_2' because that condition is already covered by AND id!='$id' .

2. The second query will return no rows if table has just one row or if in all rows id==$id .

Airshow

Hey.

Just wanted to point out that number should not be quoted in MySQL queries. Can cause all sorts of problems.

Assuming your $id is in fact a number:

$query = mysql_query("SELECT * FROM table WHERE id != '$id' AND id!='$id_2'");
// Should be
$query = mysql_query("SELECT * FROM table WHERE id != $id AND id != $id_2");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.