Hopefully flattery will get me everywhere... ;0)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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)


The problem comes when I want to provide the ability to edit a users access

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

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)...

if ($access$count=='checked')


}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

Any ideas or suggestions?



Re: Hopefully flattery will get me everywhere... ;0)

Mark wrote:
Quoted text here. Click to load it

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.

Re: Hopefully flattery will get me everywhere... ;0)

Nice one Jerry

Just what I needed...

You da man!


Quoted text here. Click to load it

Re: Hopefully flattery will get me everywhere... ;0)

Quoted text here. Click to load it

I guess when you are using $access$count, you would like it to be $acces1
....2...3... and so on. if it's the case, one way to use the content of a
variable (like what is hold by $count) as the name or part of a varible name
is like this:
if count is equal to 1, then it's like writing $access1


Site Timeline