Bluehost.com Web Hosting $6.95

Re: [PHP] Where am i screwing up?

This is a discussion on Re: [PHP] Where am i screwing up? within the PHP General forums, part of the PHP Programming Forums category; From: "Ryan A" <ryan@jumac.com> > I am just screwing around and getting used to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-31-2003
Cpt John W. Holmes
 
Posts: n/a
Default Re: [PHP] Where am i screwing up?

From: "Ryan A" <ryan@jumac.com>
> I am just screwing around and getting used to arrays with a "foreach"

thanks
> to Michael,Jan and Evan from this list and have run into problems.
>
> My requirment is pretty simple (code is below too)
> 1)unset all the sessions that might have been set with reference to the
> hardcoded array ($vars)
> 2)if any checkboxes have been set from the previous form then set that
> session
> needless to say, its not working, am too new at this to know where my

fault
> is so any help is greatly appreciated.
>
> I have even added a few comments as to what i was thinking....tell me if i
> was wrong.
>
> **************Start code************************
> <?php
> $vars = Array('noPlatform','noPrice','noSfee','noSpace'); // this
> corresponds to the "name=" of each checkbox
>
> foreach ($vars as $key) // clear all previous sessions
> {
> if(isset($_SESSION['$key']))
> {
> unset($_SESSION['$key']);
> }
> }
> echo "done1"; //just checking program execution
>
> foreach ( $vars as $vvvv ) // if any checkboxes were checked create a
> session for them
> {
> ${$vvvv} = ( isset($_POST[$vvvv]) ? 1 : 0 );
>
> if($vvvv==1)
> {
> $_SESSION[$vvvv];
> echo $vvvv; //getting no output from here...I just put it here for
> testing
> }
> }
> echo "done2"; //just checking program execution
> ?>
>
> ****************End code************************


How about you name your checkboxes as:

name="setting[xx]"

where xx is from your $vars array above. You'll end up with

name="setting[noPlatform]" value="1"
name="setting[noPrice]" value="1"
etc...

Now, you'll have $_POST['setting'] that'll contain the checked boxes.

To put those in session:

$_SESSION['setting'] = $_POST['setting'];

To see which boxes were checked...

$checked = array_keys($_POST['setting']);
or
$checked = array_keys($_SESSION['setting']);

$checked now an array similar to your $vars above but it only contains the
values that were checked.

To find out which checkboxes were NOT checked, you could use:

$not_checked = array_diff($vars,$checked);

Easy, eh?? Hope that helps.

---John Holmes...

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 12:03 AM.


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