A more sane problem description

From: Date: Thu, 16 Jun 2005 16:21:08 +0000
Subject: A more sane problem description
Groups: php.general 
Request: Send a blank email to php-general+get-217079@lists.php.net to get a copy of this message
Sorry, The last post I made was fairly incomprehensible. I'm trying to a) edit information which is already in an intersection table, while b) allowing the user to add new information to the intersection table The information in it is pulled from the table media_art and I grab the media_art_id, media_id and art_id. If a media_id is associated with an art_id in the table, I grab all three and make the checkbox for that media_id checked. I need to understand how I can make it so that a) if the user UNchecks the box, then the row containing that media_id will be deleted. AND b) if the user checks a new box, a new row will be inserted into the media_art table containing the media_id and the art_id. This is so far beyond my comprehension it's not even funny. This is what I have so far - thank you in advance for the help.: <?php $query = ''; $result = 0; $art_id = $_POST['art_id']; $media_art_id = $_POST['media_art_id']; //print_r($_POST); if (isset($_POST['editrecordMedia'])){ if (!empty($_POST['media_types'])) { foreach($_POST['media_types'] as $type) { $query = "UPDATE media_art SET media_id='$type', art_id='$art_id' WHERE media_art_id='$media_art_id' LIMIT 1"; print_r($query); mysql_query($query) or die(mysql_error()); } } else {echo "mediatypes is empty";} //Closes if (!empty($media_types))
    }//closes if (isset($_POST['editrecordMedia'])
//If editrecord hasn't been set, but selectcartoon has, get the cartoon's recordset //This is just to get the title for display purposes $query = "SELECT art_title FROM art WHERE art_id='$art_id'"; //end $media_query = "SELECT media.media_id, media.media_name, media_art.art_id, media_art.media_art_id FROM media LEFT JOIN media_art ON media_art.media_id=media.media_id AND media_art.art_id='$art_id'"; //These $art results are just to get the title for display purposes $art_result = mysql_query($query); $art_rows = mysql_fetch_assoc($art_result); //end $media_result = mysql_query($media_query); $checkbox_media = array (); while ($media_rows = mysql_fetch_assoc($media_result)){ $checkbox_media[] = "<input type='checkbox' name='media_types[]' value='{$media_rows['media_id']}' "; if ($media_rows['art_id'] === $art_id) { $checkbox_media[] .= "checked media_art_id='{$media_rows['media_art_id']}'"; } $checkbox_media[] .= "/>{$media_rows['media_name']} "; } ?> <table align="center">
        <tr><th colspan="4">Main Menu</th></tr>
    <tr>
        <td><a href="addrecord.php">Add A Record</a></td>
        <td><a href="chooserecord.php">Edit A Record</a></td>
        <td><a href="deleterecord.php">Delete A Record</a></td>
    </tr>
</table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="editrecordMedia"> <input type="hidden" name="art_id" value="<?php echo $art_id ;?>"> Choose media related to <strong><?php echo $art_rows['art_title'];?></strong><br /><br /> Media: <?php echo join($checkbox_media); ?> <input type="submit" name="editrecordMedia" value="Update">
    </form>


« previous php.general (#217079) next »