hi frens..

i have this piece of code, which is not working the way i thot it would. i want to check if the $key exists in array $rowid, where $key also comes from database.
lets say, key exists for the 1st iteration (it prints exist), but if key exists for 2nd and further iteration it doesnt print. why is it happening like this?? is there any other way i could do this? where am i going wrong??

foreach($_POST['rowid'] as $temp)
{
	$rowid[]=$temp;
}

for($i=0;$i<count($rowid);$i++)
{
	echo "rowid=".$rowid[$i]."<br>";

}


$query1="select id from purchase_order_detail where purchase_order_id='".$id."'";
result1 = mysql_query($query1);
$key=0;
while($row1 = mysql_fetch_array($result1))
{
	$key = $row1['id'];
	echo "key=".$key."<br>";
	if((array_key_exists($key, $rowid)))
        {
		echo "key exists"."<br>";
		
	}
}

it would be very helpful, if you could go thru the code an shed some light on how to solve this issue.

thanks

Recommended Answers

All 4 Replies

Member Avatar for diafol
(array) $rowid = $_POST['rowid'];

foreach($rowid as $r){
  echo "rowid = $r <br />";
}
  
$query1="select id from purchase_order_detail where purchase_order_id='".$id."'";
result1 = mysql_query($query1);
while($row1 = mysql_fetch_array($result1)){
   $key = $row1['id'];
   echo "key=".$key."<br>";
   if(in_array($key, $rowid)){
      echo "key exists <br />";
   }
}

hey ardav, thanks for the quick reply, but no change in result.

Member Avatar for diafol

OK, I just spotted an error:

result1 = mysql_query($query1);

Should be

$result1 = mysql_query($query1);

Doh!

hey aardav, thanks, that helped a lott..

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.