|
Posted by Jack Jackson on 06/17/05 02:47
Thanks, Joe!
I see what you weer going after. I had several problems including the
fact that I really didn't understand what I was trying to do until after
I did it. And I had some log errors a friend helped with.
What I needed to do was delete the media types from the intersection
table and then insert them anew; that way I don't have to do all sorts
of looping through finding the status of checked and unchecked boxes etc.
Eventually I came to:
if (isset($_POST['editrecordMedia'])){
if (!empty($_POST['media_types'])) {
//TO make sure art_id isn't empty
if (!empty($art_id)) { //delete media_art entries for this art_id
$query="DELETE FROM media_art WHERE art_id='$art_id'";
mysql_query($query);
$query = "INSERT INTO `media_art`
(`media_id`,`art_id`) VALUES ";
$sep = "";
foreach($_POST['media_types'] as $type)
{
$query .= "$sep ('$type','$art_id')";
$sep = ", ";
Anyway, thanks so much for your help!!
JJ
Joe Harman wrote:
> if ($media_rows['art_id'] === $art_id) {
> $checkbox_media[] .= "checked ";
> }
>
> $checkbox_media[] .= "/>{$media_rows['media_name']} ";
>
>
> if think you only need 2 '=' signs... i do this alot with arrays of
> check boxes .. now don't quote me on this... but i do something like
> this.. using arrays for the check box values
>
> if($permissions_data <> NULL)
> {
> if(in_array($row_rsPermissions['permission_short_name'], $permissions_data))
> { $checked_per = " checked"; } else { $checked_per = ""; }
> }
>
> hope that helps you out
> Joe
>
> On 6/16/05, Jack Jackson <jackson.linux@gmail.com> wrote:
>
>>hi,
>>I'm severely frustrated and perhaps you can help with what I have done
>>wrong. The checkboxes I use to populate an intersection table work to
>>add the records, and now I am trying to update them. It's almost there
>>but producing some unexpected results when the form is submitted: the
>>idea is that it displays the checkboxes as pre-selected if they're
>>associated with the art_id in the intersection table. They're now
>>appearing as all unselected. Any help is appreciated.
>>
>><?php
>>
>>$query = '';
>>$result = 0;
>>$art_id = $_POST['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'";
>>var_dump($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
>> 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 ";
>> }
>>
>> $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>
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
Navigation:
[Reply to this message]
|