Jump to content

Recommended Posts

Hi guys,

 

I'm trying to search an array to show if a user is attending an event ID and output "You are attending this event".

 

I need to search the array 'data', then all the numbers, then check if the 'id' matches and if they 'attending' or 'not attending'.

 

I have figured out how to search the array using:

 

<?php
echo ((in_array('107510232628186', $movies['data'][]['id']))? 'You are attending the event' : 'You are not attending the event');
?> 

 

but it only outputs an error as I don't know how to search all the middle numbered arrays.

 

Here is my array:

 

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => Test2
                    [id] => 137233316308949
                    [rsvp_status] => attending
                )

            [1] => Array
                (
                    [name] => Party Animals
                    [id] => 107510232628186
                    [rsvp_status] => attending
                )

            [2] => Array
                (
                    [name] => Ibiza Opening Party @ EDEN [TICKETS]
                    [id] => 111456325542560
                    [rsvp_status] => attending
                )

        )

 

Think I'm probably missing a trick here, as it seems like it should be simple!

 

Hope someone can help :)

 

what is it for? the current user or all users?

 

Use a loop:

all:

foreach($movies['data'] as $user){
      echo($user['name']." is ".($user['rsvp_status'] == "attending")? "Attending" : "Not Attending");
}

 

-cb-

Cool thanks for the code - so it now shows attending three times, but I need to show only for one event id which is 'id'.

 

So I need to search for '107510232628186' in the array and then check if the 'rsvp_status' of this is attending and show this.

 

Any pointers?

Thanks jcbones.

 

Thing is, I'm still getting attending three times. I think I need to move down one level in the array. $movies['data'] as $user would be the numbered arrays [0],[1],[2] not inside of those numbered arrays.

 

Hence why it is showing attending three times.

 

How can I get down one level?

 

Thanks!

I'm sure you mean your getting attending once, and not attending twice.

 

If you are getting attending 3 times then there is 3 rows with the same id?

 

anyway i think what you want is to put an "if" statement inside the "foreach" loop. If the "$user['id']" is equal to the selected "id" then echo the result (Attending or not attending).

 

-cb-

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.