Re: compare arrays problem

From: Date: Mon, 19 Feb 2001 21:04:18 +0000
Subject: Re: compare arrays problem
Groups: php.general 
Request: Send a blank email to php-general+get-40629@lists.php.net to get a copy of this message
Thank you Tim and Richard. With your help I was able to figure out how to get this script working as I intended. Here's the code, in case anyone wants to do something similar in the future. :-)) $pages=mysql_query("SELECT CP.page_id, pagename FROM cluster_pagetbl as CP, pagetbl WHERE CP.cluster_id = '$id' AND CP.page_id=pagetbl.page_id order by page_id"); $pgids= array(); if (mysql_Numrows($pages)>0) { $prows=mysql_NumRows($pages); $i=0; while ($i<$prows){ //figure out how to get page ids into array $pid= mysql_result($pages,$i, page_id); $pagename =mysql_result($pages, $i, pagename); $pgids[$pid] = $pagename; $i++; } } //prints what is in the pgid array. foreach($pgids as $pid => $pagename){ print $pid.' => '.$pagename.'<br>'; } $query2=mysql_query("select page_id, pagename FROM pagetbl order by page_id"); $mpgids= array(); if (mysql_Numrows($query2)>0) { $numrows=mysql_NumRows($query2); $x=0; while ($x<$numrows){ $mpid=mysql_result($query2,$x, page_id); $mpagename=mysql_result($query2,$x, pagename); $mpgids[$mpid] = $mpagename; $x++; } } //prints the checkboxes, compares pgids and mgids array foreach ($mpgids as $mpid => $mpagename){ print '<input type=checkbox name=page_ids[] value="'.$mpid.'"'; if ($pgids[$mpid] == $mpgids[$mpid]){ print " checked"; } print '>'.$mpagename; } //double check to see what values are in both arrays, then print it. $diff = array_intersect($mpgids,$pgids); foreach ($diff as $element){ print '<p>'.$element.'<br>';}

« previous php.general (#40629) next »