0

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

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by puvi
0
(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 />";
   }
}
0

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

0

OK, I just spotted an error:

result1 = mysql_query($query1);

Should be

$result1 = mysql_query($query1);

Doh!

0

hey aardav, thanks, that helped a lott..

Edited by puvi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.