Page 1 of 1

in_array with multiple select

Posted: Sun Mar 26, 2006 6:38 am
by AYYASH

Code: Select all

$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.

Posted: Sun Mar 26, 2006 9:38 am
by feyd
$actaddname will only be the last record found.

Posted: Sun Mar 26, 2006 3:24 pm
by AYYASH
Thanks for your reply. The doctor could figure out the problem but the patient is still need the treatment. :wink:

My mind is a mess. I've just started writing codes 2 months ago. Before that all I know about PHP or programming in general is they are exist.
I'm trying hard to learn but sometimes I need someone to push me just a little.

Posted: Sun Mar 26, 2006 3:26 pm
by s.dot
well, while your code is looping its resetting $actaddname to the latest record found with mysql_result().. thus giving you the last record on the last iteration through the loop

you should do something like this

Code: Select all

$i=0; 
$actaddname = array();
while ($i < $num) { 
   $actaddname[] = mysql_result($query, $i, "actadd_name"); 
   $i++; 
 }

Posted: Mon Mar 27, 2006 4:56 am
by AYYASH
Thanks scottayy,

The out put from your suggestion will be like this:

Code: Select all

Array ( [0] => value 1)
Array ( [0] => value 1 [1] => value 2)
It gave me 2 arrays.

Posted: Mon Mar 27, 2006 1:01 pm
by AYYASH
It worked fine but this is taking more of the server memory. Is there any other way to make the result in one array only?