in_array with multible select "PHP"

AYYASH's picture

He has: 10 posts

Joined: Jan 2004

<?php
$i
=0;
while (
$i < $num) {
  
$actaddname = mysql_result($query, $i, \"actadd_name\");
  
$i++;
}
while (
$row_add = mysql_fetch_array($add_tool)) {
  
$addtool = $row_add['addtool_name'];
     if (FALSE != 0 && in_array(
$addtool, $actaddname)) {
        
$selected = \" selected\";
     } else {
        
$selected = \"\";
  }
 
   print \"
$selected ----- $addtool <br />\";
 
}
?>
This is an update page. It should copmare values have been selected before with all values. The selected values are in new table. It doesn't work this way.
I'm sure there is something I didn't do here.

They have: 36 posts

Joined: Mar 2006

One thing the leaps out at me is FALSE != 0, FALSE always equals 0 so it's never going to match anything.

AYYASH's picture

He has: 10 posts

Joined: Jan 2004

I've figuered out the problem and solve it. The way I did it before is going to take only the last result of the loop. I should take the result of the while loop and put into array.
so itshould be something like this:

<?php
$i
=0;
$actaddname = array();
while (
$i < $num) {
  
$actaddname[] = mysql_result($query, $i, \"actadd_name\");
  
$i++;
}
?>
The FALES != 0 is to solve a problem while using in_array function. Without FALSE !=0 it will ignore the first matching result and jump to second.

Thanks for your reply.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.