in_array with multiple select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AYYASH
Forum Newbie
Posts: 16
Joined: Sat Aug 14, 2004 2:33 am

in_array with multiple select

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$actaddname will only be the last record found.
AYYASH
Forum Newbie
Posts: 16
Joined: Sat Aug 14, 2004 2:33 am

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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++; 
 }
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
AYYASH
Forum Newbie
Posts: 16
Joined: Sat Aug 14, 2004 2:33 am

Post 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.
AYYASH
Forum Newbie
Posts: 16
Joined: Sat Aug 14, 2004 2:33 am

Post 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?
Post Reply