Re: [PHP] session_name("CCLTrolley")

2005-10-04 Thread Jasper Bryant-Greene

John Taylor-Johnston wrote:

I ended up going with this. Wasn't sure how to use list anyhow. Look good?

$sql = 'SELECT * FROM '.$table.' ORDER BY RNum;';
echo "";

$news = mysql_query($sql);

   while ($mydata = mysql_fetch_object($news))
 {
foreach ($_SESSION['TrolleyContents'] as $value)
if ($value == $mydata->RNum)
{
}
  }



Why not replace the foreach and if combo inside the while with:

if( array_search( $mydata->RNum, $_SESSION['TrolleyContents'] ) !== 
false ) {


}

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-04 Thread John Taylor-Johnston

Robert Cummings wrote:


On Mon, 2005-10-03 at 18:08, John Taylor-Johnston wrote:
 


>Use "foreach" to traverse the array and display each trolly entry nicely

   


If list() works for you it's fine. I don't really use it so not entirely
sure of it's functionality with respect to looping.
 


I ended up going with this. Wasn't sure how to use list anyhow. Look good?

$sql = 'SELECT * FROM '.$table.' ORDER BY RNum;';
echo "";

$news = mysql_query($sql);

   while ($mydata = mysql_fetch_object($news))
 {
foreach ($_SESSION['TrolleyContents'] as $value)
if ($value == $mydata->RNum)
{
}
  }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-04 Thread Robert Cummings
On Mon, 2005-10-03 at 18:08, John Taylor-Johnston wrote:
>  >Use "foreach" to traverse the array and display each trolly entry nicely
> 
> This might be cleaner? I'm not sure if I'm using while and list right, 
> but somehting like that?
> 
> $glquery = mysql_query($sql);
> while ($mydata = mysql_fetch_object($glquery)) {
> 
>   while (list($_SESSION['TrolleyContents'], $value) = $mydata->RNum)
>   {
>   echo "$mydata->RNum - $mydata->field1: $mydata->field2.";
>   }
> 
> }

If list() works for you it's fine. I don't really use it so not entirely
sure of it's functionality with respect to looping.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread John Taylor-Johnston

>Use "foreach" to traverse the array and display each trolly entry nicely

This might be cleaner? I'm not sure if I'm using while and list right, 
but somehting like that?


$glquery = mysql_query($sql);
while ($mydata = mysql_fetch_object($glquery)) {

 while (list($_SESSION['TrolleyContents'], $value) = $mydata->RNum)
 {
 echo "$mydata->RNum - $mydata->field1: $mydata->field2.";
 }

}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread John Taylor-Johnston

In the search results, I use something longwinded:




You are talking about doing this, below. It looks a little clunky, 
doesn't it?


foreach ($_SESSION['TrolleyContents'] as $value) {

$sql = "select * where RNum= $value";
$news = mysql_query($sql1) or die ...
  while ($mydata = mysql_fetch_object($news))
  {
  echo "$mydata->RNum - $mydata->field1: $mydata->field2.";
  }
}

Thanks,
John



Robert Cummings wrote:


On Mon, 2005-10-03 at 16:38, John Taylor-Johnston wrote:
 


Robert Cummings wrote:
>I took a look at your link and it appears to be working fine, though you
>haven't yet wired up the viewcart.php

When I create viewcart.php, what is the best way to extract and display 
the contents of $_SESSION['TrolleyContents'] ?


Do I use my $sql value?
or in my while statement where
$mydata->RNum = $_SESSION['TrolleyContents'][??]] echo $mydata->RNum, 
$mydata->field1, $mydata->field2


Do I implode or explode $_SESSION['TrolleyContents']?
   



Use "foreach" to traverse the array and display each trolly entry nicely
(probably as you do in the search results).

 





Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread Robert Cummings
On Mon, 2005-10-03 at 16:38, John Taylor-Johnston wrote:
> Robert Cummings wrote:
>  >I took a look at your link and it appears to be working fine, though you
>  >haven't yet wired up the viewcart.php
> 
> When I create viewcart.php, what is the best way to extract and display 
> the contents of $_SESSION['TrolleyContents'] ?
> 
> Do I use my $sql value?
> or in my while statement where
> $mydata->RNum = $_SESSION['TrolleyContents'][??]] echo $mydata->RNum, 
> $mydata->field1, $mydata->field2
> 
> Do I implode or explode $_SESSION['TrolleyContents']?

Use "foreach" to traverse the array and display each trolly entry nicely
(probably as you do in the search results).

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread John Taylor-Johnston

Robert Cummings wrote:
>I took a look at your link and it appears to be working fine, though you
>haven't yet wired up the viewcart.php

When I create viewcart.php, what is the best way to extract and display 
the contents of $_SESSION['TrolleyContents'] ?


Do I use my $sql value?
or in my while statement where
$mydata->RNum = $_SESSION['TrolleyContents'][??]] echo $mydata->RNum, 
$mydata->field1, $mydata->field2


Do I implode or explode $_SESSION['TrolleyContents']?

John


$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
$sql = select * where RNum ... ?
$news = mysql_query($sql1) or die ...
   while ($mydata = mysql_fetch_object($news))
   {
while $_SESSION['TrolleyContents'][??]
echo $mydata->RNum -
   }

echo implode( ',', $_SESSION['TrolleyContents'] );  gives me a comma 
delimited.

http://ca3.php.net/explode
http://ca3.php.net/implode

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread Robert Cummings
On Mon, 2005-10-03 at 14:51, John Taylor-Johnston wrote:
> Is that over kill? No matter how I slam it, still referring to my 
> Frankensteinian merge, "unset" does the job.
> http://testesp.flsh.usherbrooke.ca/db/trolley.php
> But then again, I will not require a quanity of items. The visitor will 
> only want one copy of a bibliographic entry :-\ - I hope?!
> You were checking to see if there was a greater than 1 quantity of 
> post[RNum], right?

Yep the frankensteinian version should work fine if you never want a
quantity greater than one, I was just trying to head off problems before
they occurred, but confused the issue since you don't need quantities :)

I took a look at your link and it appears to be working fine, though you
haven't yet wired up the viewcart.php page :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread John Taylor-Johnston
Is that over kill? No matter how I slam it, still referring to my 
Frankensteinian merge, "unset" does the job.

http://testesp.flsh.usherbrooke.ca/db/trolley.php
But then again, I will not require a quanity of items. The visitor will 
only want one copy of a bibliographic entry :-\ - I hope?!
You were checking to see if there was a greater than 1 quantity of 
post[RNum], right?

Thanks,
John

   //Delete an entry:
   if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
   {
   #$_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
   #if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
   #{
   unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
   #}
   }

Robert Cummings wrote:


Thanks for your time and patience,
John
   


The expression:
   $trolley[$item] -= $quantity;
is a short form for the following:
   $trolley[$item] = $trolley[$item] - $quantity;
Essentially we decrease the quantity of the given item by $quantity.
if( $trolley[$item] < 1 )
{
#Above we check if we subtracted more items than is physically possible
unset( $trolley[$item] );
#If there are 0 or less items then there's no point having 0 of the item
#in the trolley, so we unset the item from the array, which essentially
#removes it completely. To view the difference at each step you can do
#the following:

";
   trolleyPrint();

   $trolley[$item] -= $quantity;

   echo "Trolley after removing $quantity of $item";
   trolleyPrint();

   if( $trolley[$item] < 1 )
   {
   unset( $trolley[$item] );

   echo "Trolley after cleaning up empty entry for $item";
   trolleyPrint();
   }
}

?>

Cheers,
Rob.
 



--
John Taylor-Johnston
-
"If it's not Open Source, it's Murphy's Law."

 ' ' 'Collège de Sherbrooke:
ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
   - 819-569-2064

 °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
/(_)\  Université de Sherbrooke
 ^ ^   http://compcanlit.ca/ T: 819.569.2064



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread Robert Cummings
On Mon, 2005-10-03 at 14:11, John Taylor-Johnston wrote:
> Excellent. Thanks. I think I follow what you have done. But to
> clarify, and learn, what are you doing with -= ?
> $trolley[$item] -= $quantity;
> Likewise, i had not followed what you were doing with the lines I
> commented out. They did not seem to work, and I succeeded in doing
> what I wanted without them. I'm a prof, as you can tell, and always
> have a question for an answer ;).
> Thanks for your time and patience,
> John

> > if( isset( $trolley[$item] ) )

"isset" checks that the item with ID $item is in the trolley. No need to
decrease the quantity if it's not there.

> > {
> > $trolley[$item] -= $quantity;

The expression:

$trolley[$item] -= $quantity;

is a short form for the following:

$trolley[$item] = $trolley[$item] - $quantity;

Essentially we decrease the quantity of the given item by $quantity.

> > if( $trolley[$item] < 1 )
> > {

Above we check if we subtracted more items than is physically possible
:)

> > unset( $trolley[$item] );

If there are 0 or less items then there's no point having 0 of the item
in the trolley, so we unset the item from the array, which essentially
removes it completely. To view the difference at each step you can do
the following:

";
trolleyPrint();

$trolley[$item] -= $quantity;

echo "Trolley after removing $quantity of $item";
trolleyPrint();

if( $trolley[$item] < 1 )
{
unset( $trolley[$item] );

echo "Trolley after cleaning up empty entry for $item";
trolleyPrint();
}
}

?>

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread John Taylor-Johnston
Excellent. Thanks. I think I follow what you have done. But to clarify, 
and learn, what are you doing with -= ?

$trolley[$item] -= $quantity;
Likewise, i had not followed what you were doing with the lines I 
commented out. They did not seem to work, and I succeeded in doing what 
I wanted without them. I'm a prof, as you can tell, and always have a 
question for an answer ;).

Thanks for your time and patience,
John

  //Delete an entry:
  if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
  {
  #$_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
  #if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
  #{
  unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
  #}
  }

Robert Cummings wrote:


On Sun, 2005-10-02 at 01:01, Robert Cummings wrote:


If you go with an array system might I suggest the following change to
what I wrote:



I'm resending a better way to do the simple trolley since you seemed to
have created a Frankensteinian merge of the two examples I sent
previously.
if( isset( $trolley[$item] ) )
{
$trolley[$item] -= $quantity;

if( $trolley[$item] < 1 )
{
unset( $trolley[$item] );
}
}





Re: [PHP] session_name("CCLTrolley")

2005-10-03 Thread Robert Cummings
On Sun, 2005-10-02 at 01:01, Robert Cummings wrote:
>
> If you go with an array system might I suggest the following change to
> what I wrote:

I'm resending a better way to do the simple trolley since you seemed to
have created a Frankensteinian merge of the two examples I sent
previously. This version uses functions which should probably be put
into their own source file and included (let's call it lib.trolley.php).

\n"
.implode( ',', array_keys( $_SESSION['TrolleyContents'] ) )
."\n\n";
}

?>

Now the following would facilitate the action you appear to be
performing in your example for adding to the trolley:

';

if( 'add' == $_POST['ShopAction'] )
{
echo 'Adding '.$_POST['RNum'].'...';

trolleyItemAdd( $_POST['RNum'], 1 );
}
else
if( 'delete' == $_POST['ShopAction'] )
{
echo 'Deleting '.$_POST['RNum'].'...';

trolleyItemRemove( $_POST['RNum'], 1 );
}
}
else
{
echo 'No action specified!!';
}

trolleyPrint();

?>

-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-02 Thread John Taylor-Johnston

This is what you recommended.


Is there a reason you're using a comma delimited string? I would
recommend using an array instead:



This is what I implemented? Where did I go wrong?
John



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-02 Thread John Taylor-Johnston

>This is the old version I demonstrated. You should go with the later
>version that sets the values to the quantity :)

I thought I had? Haven't I?
But this is the easiest shopping cart I have ever seen.
However, I still have not understood what you were doing with these 
lines I commented out.


   if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
   {
   #$_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
   #if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
   #{
   unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
   #}

They did not work, or seem to?

John

---snip
http://testesp.flsh.usherbrooke.ca/db/trolley.php

Array
(
[TrolleyContents] => Array
(
[2378] => 2378
[2504] => 2504
)
)
)

---snip
";

if("add" == $_POST['ShopAction'])
{
   echo "adding ...";
   // Add new entry:

   if( isset( $_POST['RNum'] ) )
   {
   $_SESSION['TrolleyContents'][$_POST['RNum']] = $_POST['RNum'];
   }
   echo implode( ',', $_SESSION['TrolleyContents'] );

   #echo $_POST['RNum']."!!";
}else{
   echo "deleting ...";
   //Delete an entry:
   if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
   {
   #$_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
   #if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
   #{
   unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
   #}
   }
}
print_r( $_SESSION );
?>

Delete form: snip ---



alt="Delete" title="Delete" style="padding-right: 
5px;">Delete


Add form: snip ---



alt="Add to cart" title="Add to cart" style="padding-right: 
5px;">Add to cart


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-02 Thread Robert Cummings
On Mon, 2005-10-03 at 00:16, John Taylor-Johnston wrote:
>  >Warning: Bad arguments to implode() in /var/.../printtrolley.php on 
> line 14
>  >Array ( [TrolleyContents] => 1 3 4 4 5 6 )
> 
> I restarted Mozilla and tried again.
> It's ok now.
> Thanks for your time.

The old session was probably still populated with the string version.

> 
> Array
> (
> [TrolleyContents] => Array
> (
> [16] => 16
> [30] => 30
> [47] => 47
> [76] => 76
> [368] => 368
> [1687] => 1687
> [1939] => 1939
> [1761] => 1761
> [1880] => 1880
> [1936] => 1936
> )
> 
> )

This is the old version I demonstrated. You should go with the later
version that sets the values to the quantity :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-02 Thread John Taylor-Johnston
>Warning: Bad arguments to implode() in /var/.../printtrolley.php on 
line 14

>Array ( [TrolleyContents] => 1 3 4 4 5 6 )

I restarted Mozilla and tried again.
It's ok now.
Thanks for your time.

Array
(
   [TrolleyContents] => Array
   (
   [16] => 16
   [30] => 30
   [47] => 47
   [76] => 76
   [368] => 368
   [1687] => 1687
   [1939] => 1939
   [1761] => 1761
   [1880] => 1880
   [1936] => 1936
   )

)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-02 Thread John Taylor-Johnston

Robert Cummings wrote:


Is there a reason you're using a comma delimited string? I would
recommend using an array instead:



Cheers,
Rob.
 



Hi,
Still absorbing this array stuff :).
I'm getting this error. And when RNum = 1 or = 16 or = 116, it only 
registers '1', or whatever the first digit is.


Warning: Bad arguments to implode() in /var/.../printtrolley.php on line 14
Array ( [TrolleyContents] => 1 3 4 4 5 6 )

I was expecting to see soemthing like:

TrolleyContents[16]
TrolleyContents[32]
TrolleyContents[45]
TrolleyContents[48]
TrolleyContents[55]
TrolleyContents[116]

if I have done my homework, since last night ;), correctly?

The manual example says:


What is my correct seperator? And why does only one digit get registered?

Thanks,
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston

Robert Cummings wrote:


To decrement the quantity of an item in the trolley:
RNum] ) )
{
   $_SESSION['TrolleyContents'][$myData->RNum] -= 1;
   if( $_SESSION['TrolleyContents'][$myData->RNum] <= 0 )
   {
   unset( $_SESSION['TrolleyContents'][$myData->RNum] );
   }
}
?>
I'll leave it as an exercise for you to add or delete X quantity.
Cheers,
Rob.
 


Thanks. Always willing to learn,
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sun, 2005-10-02 at 00:37, John Taylor-Johnston wrote:
> Robert Cummings wrote:
> 
> >  > session_name( 'CCLTrolley' );
> > session_start();
> > // Initialize the trolley.
> > if( !isset( $_SESSION['TrolleyContents'] ) )
> > {
> > $_SESSION['TrolleyContents'] = array();
> > }
> > // Add new entry.
> > if( isset( $_POST['AddToTrolley'] ) )
> > {
> > $_SESSION['TrolleyContents'][$_POST['AddToTrolley']] = 
> > $_POST['AddToTrolley']
> > }
> > echo implode( ',', $_SESSION['TrolleyContents'] );
> > ?>
> 
> I've never been very good getting my head around arrays.
> Then how do I check to know if $mydata->RNum is in 
> $_SESSION['TrolleyContents'] ?
> Thanks for your patience.

If you go with an array system might I suggest the following change to
what I wrote:



To check if something is in the trolley:

RNum] ) )
{
echo 'Yay!';
}
?>

To decrement the quantity of an item in the trolley:

RNum] ) )
{
$_SESSION['TrolleyContents'][$myData->RNum] -= 1;
if( $_SESSION['TrolleyContents'][$myData->RNum] <= 0 )
{
unset( $_SESSION['TrolleyContents'][$myData->RNum] );
}
}
?>

I'll leave it as an exercise for you to add or delete X quantity.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sun, 2005-10-02 at 00:41, John Taylor-Johnston wrote:
> Robert Cummings wrote:
> 
> > And $_SESSION instead of session_register and always access your session
> > vars through $_SESSION.
> 
> I'm safe with "PHP Version 4.1.2" ?

Should be. The docs state that the $_XXX series of vars were introduced
in PHP 4.1.0.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston

Robert Cummings wrote:


And $_SESSION instead of session_register and always access your session
vars through $_SESSION.


I'm safe with "PHP Version 4.1.2" ?
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston

Robert Cummings wrote:


$_SESSION['TrolleyContents'][$_POST['AddToTrolley']] = 
$_POST['AddToTrolley']

}
echo implode( ',', $_SESSION['TrolleyContents'] );
?>


I've never been very good getting my head around arrays.
Then how do I check to know if $mydata->RNum is in 
$_SESSION['TrolleyContents'] ?

Thanks for your patience.
John

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sun, 2005-10-02 at 00:32, John Taylor-Johnston wrote:
> >  >
> > session_name( 'CCLTrolley' );
> > session_start();
> >
> > //
> > // Initialize the trolley.
> > //
> > if( !isset( $_SESSION['TrolleyContents'] ) )
> > {
> >$_SESSION['TrolleyContents'] = '';
> > }
> >
> > //
> > // Add new entry.
> > //
> > if( isset( $_POST['AddToTrolley'] ) )
> > {
> >if( $_SESSION['TrolleyContents'] ) == '' )
> >{
> >$_SESSION['TrolleyContents'] = $_POST['AddToTrolley'];
> >}
> >else
> >{
> >$_SESSION['TrolleyContents'] .= ','.$_POST['AddToTrolley'];
> >}
> > }
> >
> > echo $_SESSION['TrolleyContents'];
> >
> > phpinfo();
> >
> > ?>
> 
> 
> Robert Cummings wrote:
> 
> >John Taylor-Johnston wrote:
> >  
> >
> >>Robert Cummings wrote:
> >>
> >>Why is it outdated semantics?
> >>
> >>
> >>
> >
> >Might i refer you to:
> >
> >http://ca.php.net/manual/en/language.variables.predefined.php
> >http://ca.php.net/manual/en/function.session-register.php
> >
> >$HTTP_POST_VARS has been considered deprecated for some time now.
> >session_register() is considered clumsy and dangerous since it is only
> >works with register_globals enabled which is itself considered poor
> >coding style in this enlightened era of PHP.
> >
> >Cheers,
> >Rob.
> >  
> >
> So use
> $_POST["AddToTrolley"]
> instead of
> $HTTP_POST_VARS["AddToTrolley"]?

And $_SESSION instead of session_register and always access your session
vars through $_SESSION.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston





Robert Cummings wrote:


John Taylor-Johnston wrote:
 


Robert Cummings wrote:

Why is it outdated semantics?

   



Might i refer you to:

http://ca.php.net/manual/en/language.variables.predefined.php
http://ca.php.net/manual/en/function.session-register.php

$HTTP_POST_VARS has been considered deprecated for some time now.
session_register() is considered clumsy and dangerous since it is only
works with register_globals enabled which is itself considered poor
coding style in this enlightened era of PHP.

Cheers,
Rob.
 


So use
$_POST["AddToTrolley"]
instead of
$HTTP_POST_VARS["AddToTrolley"]?

Thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sun, 2005-10-02 at 00:18, John Taylor-Johnston wrote:
>
> P.S. do folks prefer I reply on top or on bottom?

Some people don't care, but those that do care have loud voices and
would prefer you bottom post since they haven't yet been upgraded to
random access reading and are still hooked up to a tape drive :B

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Jasper Bryant-Greene

John Taylor-Johnston wrote:

Looks a bit odd to me :) But could be because you're using outdated
semantics. It should be sufficient to do the following:

[snip]


Why is it outdated semantics?


I believe he was referring to your use of $HTTP_POST_VARS and 
session_register, which have been replaced by $_POST and $_SESSION, 
respectively. The manual will have more details.



P.S. do folks prefer I reply on top or on bottom?


Well, I can't speak for everyone else, but personally, bottom, as long 
as you trim your posts :)


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sun, 2005-10-02 at 00:18, John Taylor-Johnston wrote:
> Robert Cummings wrote:
> 
> Why is it outdated semantics?
> 
> P.S. do folks prefer I reply on top or on bottom?

Might i refer you to:

http://ca.php.net/manual/en/language.variables.predefined.php
http://ca.php.net/manual/en/function.session-register.php

$HTTP_POST_VARS has been considered deprecated for some time now.
session_register() is considered clumsy and dangerous since it is only
works with register_globals enabled which is itself considered poor
coding style in this enlightened era of PHP.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston

Robert Cummings wrote:


On Sat, 2005-10-01 at 23:57, John Taylor-Johnston wrote:
 


$TrolleyContents is a string.
Basically what I want to accomplish here is if $TrolleyContents already 
exists append $AddToTrolley to $TrolleyContents, if not register 
$TrolleyContents.

Am I going about it right?
John


   



Looks a bit odd to me :) But could be because you're using outdated
semantics. It should be sufficient to do the following:



Is there a reason you're using a comma delimited string? I would
recommend using an array instead:


 


Why is it outdated semantics?

P.S. do folks prefer I reply on top or on bottom?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_name("CCLTrolley")

2005-10-01 Thread Robert Cummings
On Sat, 2005-10-01 at 23:57, John Taylor-Johnston wrote:
> $TrolleyContents is a string.
> Basically what I want to accomplish here is if $TrolleyContents already 
> exists append $AddToTrolley to $TrolleyContents, if not register 
> $TrolleyContents.
> Am I going about it right?
> John
> 
>  #printcontents.php
> 
> session_name("CCLTrolley");
> session_start();
> 
> if (isset($HTTP_POST_VARS["AddToTrolley"]))
> {
> $TrolleyContents = $TrolleyContents.",".$HTTP_POST_VARS["AddToTrolley"];
> }else{
> session_register("TrolleyContents");
> }
> echo $TrolleyContents;
> 
> phpinfo();
> ?>

Looks a bit odd to me :) But could be because you're using outdated
semantics. It should be sufficient to do the following:



Is there a reason you're using a comma delimited string? I would
recommend using an array instead:



Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] session_name("CCLTrolley")

2005-10-01 Thread John Taylor-Johnston

$TrolleyContents is a string.
Basically what I want to accomplish here is if $TrolleyContents already 
exists append $AddToTrolley to $TrolleyContents, if not register 
$TrolleyContents.

Am I going about it right?
John



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php