By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,407 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,407 IT Pros & Developers. It's quick & easy.

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

P: n/a
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_recor d_does_not_already_exist}
else
{query_to_remove_record_from_access_table_if_it_do es_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

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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_recor d_does_not_already_exist}
else
{query_to_remove_record_from_access_table_if_it_do es_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.
js*******@attglobal.net
==================
Jul 17 '05 #2

P: n/a
Nice one Jerry

Just what I needed...

You da man!

Mark

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:p4********************@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_recor d_does_not_already_exist}
else
{query_to_remove_record_from_access_table_if_it_do es_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.
js*******@attglobal.net
==================

Jul 17 '05 #3

P: n/a
>...
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>


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:
${"access$count"}
if count is equal to 1, then it's like writing $access1

Dae
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.