As my "learn PHP" project,  I'm setting up a version of my site to 
use it.  So far, so good.  I'm working on a relational system to 
handle what sections of my site go where in a hierarchy.

I'm able to add new rows to a table that relates categories to kinds 
of content.  That works fine, but my next step is what's confusing 
me.  I'm displaying the current subcategories ("flavors") as 
checkboxes in a form.  If they're selected, then they get passed to 
the next step and added to the relations table.  What I'd like to do, 
though, is have a checkbox already checked if there's an existing 
relation for it.

My first thought is taking the array of existing flavors and compare 
that array to the array of flavors that are children of the current 
parent category.  Array_intersect would seem to be perfect for this, 
but it's PHP4 only, right?  (I'm also open to the possibility that 
I'm approaching this in entirely the wrong way, so any contributions 
are welcome.)

Here's my existing code:

$childquery = "select * from flavors order by flavor";
$childtype = "flavor";
$childresult = mysql_query($childquery) or die(mysql_error());

//childresult behaves as expected

$relationsquery = "select * from relations where 
childtype='$childtype' and parenttype='$parenttype' and 
parentsku='$parentsku'";


$relationsresult = mysql_query($relationsquery) or die(mysql_error());

/* relationsresult is the other array I think I need; but I don't 
know what to do with it */

?>
form code goes in here, snipped for space/relevance
<?php

while ($row = mysql_fetch_array($childresult)) {

printf("<input type=\"checkbox\" name=\"childsku[]\" 
value=\"%s\">%s<br>\n", $row["flavorsku"], $row["flavor"]);

}


Any ideas/thoughts or pointers to appropriate tutorials would be most 
helpful.  Thanks!

-- 
Maurice Rickard
http://mauricerickard.com/

-- 
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