I can write this and get the right results:
if ( $_SESSION['addId'] == 'add[4]' )
$productId = 1;
if ( $_SESSION['addId'] == 'add[5]' )
$productId = 2;
if ( $_SESSION['addId'] == 'add[6]' )
$productId = 3;
But if I try to streamline it by writing it this way, it doesn't work:
if ( $_SESSION['addId'] == 'add[$i]' )
$productId = $i;
I think the two methods should be equivalent so why doesn't the second way work?
Writing a simple statement with an index
Started by makamo66, May 21 2010 04:29 PM
3 replies to this topic
#1
Posted 21 May 2010 - 04:29 PM
|
|
|
#2
Posted 21 May 2010 - 07:40 PM
#3
Posted 22 May 2010 - 04:27 PM
I'd use an preg match
preg_match("/add\[(\d)\]/", $_SESSION['addId'], $match);
$productId = $match[1];
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#4
Posted 22 May 2010 - 04:57 PM
All of the problems that I've been writing about lately had to do with the fact that I was using nine image buttons and just one form. Once I put form tags around all of my image buttons individually the problems went away.


Sign In
Create Account


Back to top









