Checkboxes From Intersection Redux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux