Checkboxes From Intersection Redux

From: Date: Tue, 14 Jun 2005 22:48:09 +0000
Subject: Checkboxes From Intersection Redux
Groups: php.general 
Request: Send a blank email to php-general+get-216981@lists.php.net to get a copy of this message
Hi, With your help I got some checkboxes generated the other day for a form. I would like some help getting a similar problem solved. I am now making a form to edit db entries made in the previous form. I have three tables involved: art, media and media_art. I need to show checkboxes for all available media. For the chosen record ($cartoon, which equals an art_id selected by the user) I must also go into the media_art table, and where the selected art ID has a corresponding media_id, display that media_id's media_name as a checked box. TABLE media: media_id media_name
   1           ink
   2           pencil
   3           watercolor
   4           gauche
   5           watercolor pencil
To find out the art_id of the chosen record, the user is selecting from a dropdown box in the form. I'm doing queries like this to make a publisher dropdown in a similar vein: $query = "SELECT * FROM art WHERE art.art_id = '$cartoon'"; $publisher_query = 'SELECT * FROM publisher'; $result = mysql_query($query); $publisher_result = mysql_query($publisher_query); while ($rows = mysql_fetch_assoc($result)){ $publisher_dropdown = '<select name="publisher_id">';
    while ($pub = mysql_fetch_assoc($publisher_result)){
    $publisher_dropdown .= '<option value="' . $pub['publisher_id'];
        if ($pub['publisher_id'] == $rows['publisher_id']){
            $publisher_dropdown .= '"  selected ';
        }
$publisher_dropdown .= '">' . htmlentities($pub['publisher_name']);
     }
$publisher_dropdown .= '</select>'; } I now need to formulate how to make the checkboxes similarly. The original setup to make the checkboxes was : $media_query = 'SELECT media_id,media_name FROM media GROUP BY media_name'; $media_result = mysql_query($media_query); $checkbox_media = array (); $media_types = array(); while ($media_rows = mysql_fetch_assoc($media_result)){ $checkbox_media[] = "<input type='checkbox' name='media_types[]' value='{$media_rows['media_id']}' />{$media_rows['media_name']} "; } Those which were checked were inserted into media_art thusly:
media_id     art_id
  3            1
  4            1
  5            1
What I want to do is say "For every media_id which is associated with $cartoon in the table media_art, check the box; for all others leave them unchecked. How can I do this? Thanks very much in advance, Jack

« previous php.general (#216981) next »