loops

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
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

loops

Post 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
	}
	          
...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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