Page 1 of 1

loops

Posted: Sat Jan 20, 2007 1:54 am
by garry27
i have an assoc array of pubs and their address properites (row)
and
I have an assoc array of pubs in a list (row2)

some of the pubs in the list may or may not match the pubs in the pubs array. what i'm trying to do is loop through the pubs array and assign a 'yes' or 'no' value to a new variable (addpub) according to whether the pubs are on the publist array or not.

can anyone help me? here's the code i have so far, but at the moment it just defaults to addpub=yes


Code: Select all

while($row)
  {
    $i++;
    extract($row);
	
	foreach ($row2 as &$val) {
	 if ($val == $pub_id) {
	  $add_pub = 'no'; //assigns 'no' value to $add_pub_link if exists in crawl
	  break 2;
	 }
    }
	
	if (!isset ($add_pub) ) {
	 $add_pub = 'yes';  //assigns 'yes' value to $add_pub_link if not
	}
	          
...

Posted: Sat Jan 20, 2007 7:54 am
by Kieran Huggins
Give each pub on the first list an ID.

Then on the second list, the row can either have a reference to the ID of the pub on list 1 or not.