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

This is a discussion on Hopefully flattery will get me everywhere... ;0) within the PHP Language forums, part of the PHP Programming Forums category; I would really appreciate some help with this. I am a PHP neophyte, so please forgive me... I am building ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-18-2005
Mark
 
Posts: n/a
Default Hopefully flattery will get me everywhere... ;0)

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





Reply With Quote
  #2 (permalink)  
Old 05-18-2005
Jerry Stuckle
 
Posts: n/a
Default Re: Hopefully flattery will get me everywhere... ;0)

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.
jstucklex@attglobal.net
==================
Reply With Quote
  #3 (permalink)  
Old 05-18-2005
Mark
 
Posts: n/a
Default Re: Hopefully flattery will get me everywhere... ;0)

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_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.
> jstucklex@attglobal.net
> ==================



Reply With Quote
  #4 (permalink)  
Old 05-19-2005
Daedalus.OS
 
Posts: n/a
Default Re: Hopefully flattery will get me everywhere... ;0)

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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0