Forum Moderators: coopster

Message Too Old, No Replies

Create Array of Items Found

         

TrishVB

6:25 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



I am doing a find of a user from a table that contains USERID, ITEMNO, etc., to find what items (services) a user presently is signed up for. What I am trying to do is create an "add services" form and instead of listing everything available, only show items/services that user isn't already signed up for. Something like:

if ($items=array($userData['ITEMNO']!="oranges") {
echo "<input type='text' name='fruit' value='oranges'>";
}

When I use this and then var_dump, I only get back the last item the user has.

Ideas?

Thanks,
Trish

TrishVB

6:28 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



Sorry, I entered that incorrectly. It was actually:

if ($userData['ITEMNO']!="oranges") {
echo...

enigma1

10:41 am on Sep 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe $userData['ITEMNO'] needs to be an array that contains the items the user signed up for. Then for each of the services you have you could do:

if( !in_array('oranges',$userData['ITEMNO']) ) {
echo "<input type='text' name='fruit' value='oranges'>";
}

if( !in_array('football',$userData['ITEMNO']) ) {
echo "<input type='text' name='ticket' value='football'>";
}
....
etc

You need to setup the $userData['ITEMNO'] somewhere as an array that contains the user previous services. So $userData['ITEMNO'][0] = 'oranges', $userData['ITEMNO'][1] = 'football' etc, ie some way of loading the md array.

TrishVB

12:12 pm on Sep 22, 2010 (gmt 0)

10+ Year Member



Thanks enigma1! I think my problem is getting just the ITEMNO's found into an array. I've ended up doing a bunch of hardcoding for each item (luckily there's only 13), with "if isset", create a variable for each one, then at the end, add all those variables into an array. I got tired of trying to figure out the "easy" way to do it.