Skip to main content
removed unnecessary text based on https://meta.stackexchange.com/q/2950/476162
Source Link
SecretAgentMan
  • 2.9k
  • 8
  • 26
  • 44

I'm developing a small module on CakePHP 3 and I'm currently encountering a small problem that I can't seem to solve.

I have two tables: Events and shop_ticket.

Events table:

I store information related to the event (id, name, description).

Shop_ticket table:

I record the elements related to the event when the ticket is purchased (user_id, event_id).

My problem is that when I try to retrieve the event-related information on my "ticket history" page, it systematically retrieves the last item for each user. I haven't found a solution to this problem yet. Does anyone have any suggestions?

Below is the latest code I've tested.

I've been trying to find a solution for several days now, and everything I've tried gives me the same result.

Thanks in advance to anyone who can help me.

$ticketTable = TableRegistry::getTableLocator()->get('ShopTicket');
            $ticket = $ticketTable->find('all', [
                'conditions' => ['ShopTicket.user_id' => $this->request->getSession()->read('Auth.User.id')]
            ]);

            foreach ($ticket as $item) {
                $eventTable = TableRegistry::getTableLocator()->get('Events');
                $event = $eventTable->find('all', [
                    'conditions' => ['Events.id' => $item->event_id]
                ]);

                $this->set('event_info', $event);
           }
            $this->set('ticketList', $ticket);

I'm developing a small module on CakePHP 3 and I'm currently encountering a small problem that I can't seem to solve.

I have two tables: Events and shop_ticket.

Events table:

I store information related to the event (id, name, description).

Shop_ticket table:

I record the elements related to the event when the ticket is purchased (user_id, event_id).

My problem is that when I try to retrieve the event-related information on my "ticket history" page, it systematically retrieves the last item for each user. I haven't found a solution to this problem yet. Does anyone have any suggestions?

Below is the latest code I've tested.

I've been trying to find a solution for several days now, and everything I've tried gives me the same result.

Thanks in advance to anyone who can help me.

$ticketTable = TableRegistry::getTableLocator()->get('ShopTicket');
            $ticket = $ticketTable->find('all', [
                'conditions' => ['ShopTicket.user_id' => $this->request->getSession()->read('Auth.User.id')]
            ]);

            foreach ($ticket as $item) {
                $eventTable = TableRegistry::getTableLocator()->get('Events');
                $event = $eventTable->find('all', [
                    'conditions' => ['Events.id' => $item->event_id]
                ]);

                $this->set('event_info', $event);
           }
            $this->set('ticketList', $ticket);

I'm developing a small module on CakePHP 3 and I'm currently encountering a small problem that I can't seem to solve.

I have two tables: Events and shop_ticket.

Events table:

I store information related to the event (id, name, description).

Shop_ticket table:

I record the elements related to the event when the ticket is purchased (user_id, event_id).

My problem is that when I try to retrieve the event-related information on my "ticket history" page, it systematically retrieves the last item for each user. I haven't found a solution to this problem yet. Does anyone have any suggestions?

Below is the latest code I've tested.

I've been trying to find a solution for several days now, and everything I've tried gives me the same result.

$ticketTable = TableRegistry::getTableLocator()->get('ShopTicket');
            $ticket = $ticketTable->find('all', [
                'conditions' => ['ShopTicket.user_id' => $this->request->getSession()->read('Auth.User.id')]
            ]);

            foreach ($ticket as $item) {
                $eventTable = TableRegistry::getTableLocator()->get('Events');
                $event = $eventTable->find('all', [
                    'conditions' => ['Events.id' => $item->event_id]
                ]);

                $this->set('event_info', $event);
           }
            $this->set('ticketList', $ticket);
edited title
Link
Ken Lee
  • 8.4k
  • 3
  • 14
  • 34

Retrieved Retrieving values ​from 2 tables at the same time in CakePHP 3

Source Link

Retrieved values ​from 2 tables at the same time

I'm developing a small module on CakePHP 3 and I'm currently encountering a small problem that I can't seem to solve.

I have two tables: Events and shop_ticket.

Events table:

I store information related to the event (id, name, description).

Shop_ticket table:

I record the elements related to the event when the ticket is purchased (user_id, event_id).

My problem is that when I try to retrieve the event-related information on my "ticket history" page, it systematically retrieves the last item for each user. I haven't found a solution to this problem yet. Does anyone have any suggestions?

Below is the latest code I've tested.

I've been trying to find a solution for several days now, and everything I've tried gives me the same result.

Thanks in advance to anyone who can help me.

$ticketTable = TableRegistry::getTableLocator()->get('ShopTicket');
            $ticket = $ticketTable->find('all', [
                'conditions' => ['ShopTicket.user_id' => $this->request->getSession()->read('Auth.User.id')]
            ]);

            foreach ($ticket as $item) {
                $eventTable = TableRegistry::getTableLocator()->get('Events');
                $event = $eventTable->find('all', [
                    'conditions' => ['Events.id' => $item->event_id]
                ]);

                $this->set('event_info', $event);
           }
            $this->set('ticketList', $ticket);
created from staging ground