|
Posted by Mark on 09/28/41 11:16
Nice one Jerry
Just what I needed...
You da man!
Mark
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:p4mdnTZAXNObNBffRVn-oA@comcast.com...
> Mark wrote:
>> I would really appreciate some help with this. I am a PHP neophyte, so
>> please forgive me...
>>
>> I am building a site that will be used to display image galleries. Some
>> galleries are public (can be viewed without logging on) while others
>> require authentication. Logged on users are able to see further galleries
>> that have been granted to them by the administrator. Different members
>> are granted access to different galleries. For example, member6 can see
>> all privategalleries, while member7 can see privategallery3 but not
>> privategallery4, and member8 can see privategallery4 but not
>> privategallery3. Hopefully you get my drift here...
>>
>> To control all this I have created several tables.
>>
>> There is a table called GALLERY that contains information about the
>> galleries on the site (Gallery Title, gallery description, path to the
>> images etc etc)
>>
>> There is also a table called MEMBERS that contains (surprisingly)
>> information about the members (email address, password, name etc etc)
>>
>> To control access to the various galleries , I have a table called
>> ACCESS, that contains two columns, ACCESSMEMBER that contains the
>> member's ID (which is the primary key from the MEMBERS table), and
>> ACCESSTO that contains the gallery ID (the primary key from the GALLERY
>> table) that they have access to.
>>
>> When the user logs on, the page that displays the available galleries
>> looks up in the ACCESS table to see which galleries they are authorised
>> to see, and provides appropriate links to those galleries. (The other
>> pages also use this table to look up whether a particular gallery or
>> image can be viewed, so sneaky users can't see images by molesting the
>> URLs)
>>
>> ALL OF THE ABOVE WORKS LIKE CLOCKWORK AND IS NOT THE POINT OF MY POST!!!
>>
>> The problem comes when I want to provide the ability to edit a users
>> access permissions.
>>
>> I have a form that prints out checkboxes for each of the gallery_ids,
>> that looks up the ACCESS table and populates the checkboxes with ticks in
>> the gallery checkbox that access has been granted to. So for example, if
>> a query to the GALLERY table says there are 10 galleries, it provides 10
>> checkboxes whose names are access1, access2, access3 etc, up to access10.
>> If the query to the ACCESS table says that this user is granted
>> permission to gallery3, gallery5 and gallery7, these boxes are checked.
>> When the form is submitted, these 10 variables are then passed onto the
>> page that updates the ACCESS table.
>>
>> THIS IS WHERE I AM SERIOUSLY STUCK!!! (Sorry it has taken so long to get
>> to the point...)
>>
>> My update page now has these 10 lovely variables. I want to produce a
>> loop of some sort that works its way through the variables and updates
>> the access table appropriately.
>>
>> I tried the following (or something quite similar)...
>>
>> $count=1;
>> do{
>> if ($access$count=='checked')
>> {query_to_insert_record_into_access_table_if_record_does_not_already_exist}
>> else
>> {query_to_remove_record_from_access_table_if_it_does_exist}
>> $count++;
>> }while ($count<$number_of_galleries+1)
>>
>> Obviously it didn't work.
>>
>> The problem was with the bit where I tried to specify the variable using
>> $access$count. I knew it wasn't going to work when I tried it. I'm really
>> stuck here. <flatter>I'm sure its quite simple to experts like you
>> </flatter>
>>
>> Any ideas or suggestions?
>>
>> TIA
>>
>> Mark
>>
>>
>>
>>
>>
> Mark,
>
> Use arrays.
>
> In your form, assume $gid contains the gallery id:
>
> <input type="checkbox" name="access[]" value="$gid">Gallery <?=$gid;?>
>
>
> Repeat for each gallery.
>
> Then when you go to process it (assuming the form is POSTed),
> $_POST['access'] will be an array containing the id's of the galleries
> which are checked (if any).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
Navigation:
[Reply to this message]
|