I am getting id's 3 times. count will be 3 but i am getting 9. i dont know where i did mistake.
any body help me

$result = mysql_query("SELECT * FROM candidate where user_id ='$username' and password='$password' and status='0' " );
$num=mysql_num_rows($result);
if($num>0)
{
$row1=mysql_fetch_array($result);
$cand_id=$row1['cand_id'];
$f_mobile=$row1['f_mobile'];

$d2=mysql_query("select  *  from parent where cand_id='$cand_id' and status='0'");
$row2=mysql_fetch_array($d2);
$father_name=$row2['father_name'];

$d3=mysql_query("select  c.cand_id, p.cand_id as cand_id
  from candidate c,parent p where c.f_mobile='$f_mobile'  and  p.father_name='$father_name' and c.status='0' and p.status='0' ");
$num1=mysql_num_rows($d3);
echo $num1."<br>";
if($num1>1) 
{
while($row3=mysql_fetch_array($d3))
{
$cand_id=$row3['cand_id'];
echo $cand_id."<br>";
}

}
}

Any body help me i am getting o/p is
count 9
1
17
18
1
17
18
1
17
18

but i want count is 3
and 1
17
18

to solve your problem you have to export the table schema and data and explain what do you want to do, no one can figure out from a not working sql what do you really expect!

some solutions
1)
in the 3th sql add
and c.cand_id = p.cand_id

2)
the 3th query can also be rewriten as

where c.cand_id = p.cand_id and c.cand_id = '$cand_id'

dont know why you need the p.status = '0' have you multiple records in parent with the same cand_id?

3)
try to add at the end from 3th sql
group by c.cand_id, p.cand_id

as you see it can very confused

George

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.