Professional Web Applications Themes

Hopefully flattery will get me everywhere... ;0) - PHP Development

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

  1. #1

    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





    Mark Guest

  2. #2

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

    Mark wrote: 
    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.
    net
    ==================
    Jerry Guest

  3. #3

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

    Nice one Jerry

    Just what I needed...

    You da man!

    Mark

    "Jerry Stuckle" <net> wrote in message
    news:com... 
    > 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.
    > net
    > ==================[/ref]


    Mark Guest

  4. #4

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

    >... 

    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


    Daedalus.OS Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139