I am hoping that someone really understands arrays reads this and can tell
me why the following isn't working as I expect it to. I've been trying for
days to get it to work. 

$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");

/*
SQL Result for $id=1:
page_id pagename 
 1   breakingnews  
 3   weather  
*/
 
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= array("$pid" => "$pagename");

foreach($pgids as $pid => $pagename){
 print $pid.' => '.$pagename.'<br>';
}

/* prints:
1 => breakingnews
3 => weather

At this point the correct number of values appear to be in the pgids array
*/

$i++;
}
}

$query2=mysql_query("select page_id, pagename FROM 
pagetbl order by page_id");

/*
SQL Result:
page_id pagename 
 1   breakingnews  
 2   pastnews  
 3   weather 
*/

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= array("$mpid" => "$mpagename");   
  
foreach ($mpgids as $mpid => $mpagename){
print '<input type=checkbox name=page_ids[] value="'.$mpid.'"';

if ($pgids == $mpgids){         print " checked"; }
print '>'.$mpagename;
}

// prints out three checkboxes, since that's the total number of pages
present
//but only the third checkbox (weather) gets checked, the first one should
be checked also

$x++;
}
}

//I used the array intersect function to doublecheck what is going on and it
finds only weather also
//What is happening to the first value?

$diff = array_intersect($mpgids,$pgids);

foreach ($diff as $element){
print '<p>'.$element.'<br>';} 
 
//prints: weather

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to