Question

this is my first time on StackOverflow and i was wondering if anyone could help me with the following scenario.

I have a joomla website running the RS Events Pro component. The way it works is i post a list of events, people can search for an event and like google it displays a list of results. From the results you can click in to it to purchase tickets and view more details.

Now on the results page i want to add a small function which would state of tickets are available or if the event is sold out.

I have created the following code, but i want to merge the results because for example: event one might have 3 separate types of tickets. the first type might be sold out so my query returns the following: 'Sold Out. available. available.'

I want it so it only displays 'sold out' if all tickets have sold out.

Is there anyway you can merge the results from a database column because if you can, maybe i could merge all available tickets for a given event and if its >= 1 then i could display 'available tickets'.

<?php
            $db = &JFactory::getDBO();
            $db->setQuery("SELECT * FROM #__rseventspro_tickets WHERE ide = '".$event->id."'");
            $tickets = $db->loadObjectList();

              foreach($tickets as $ticket)
              {
                if($ticket->seats >= '1'){
                    echo('Tickets available. ');

                }
                else{
                    echo('Sold out. ');
                }

              } 
              ?>

Here is my database table dump - i hope this helps:

--
-- Table structure for table `tkmrf_rseventspro_tickets`
--

CREATE TABLE IF NOT EXISTS `tkmrf_rseventspro_tickets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ide` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `price` float NOT NULL,
  `seats` int(10) NOT NULL,
  `user_seats` int(10) NOT NULL,
  `description` text NOT NULL,
  `position` text NOT NULL,
  `groups` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=27 ;

--
-- Dumping data for table `tkmrf_rseventspro_tickets`
--

INSERT INTO `tkmrf_rseventspro_tickets` (`id`, `ide`, `name`, `price`, `seats`, `user_seats`, `description`, `position`, `groups`) VALUES
(19, 65, 'Standard', 5, 190, 0, 'Standard ticket for entry to the club.', '', ''),
(20, 65, 'VIP Tables', 50, 10, 0, 'Get the VIP treatment! \r\nYour very own table and a bottle of Champagne to get you started.', '', ''),
(23, 68, 'Standard', 5, 0, 0, 'standard entry. prices are higher on the door.', '', ''),
(22, 67, 'Fast-Track', 5, 0, 0, 'Queue jump with the fast track tickets!', '', ''),
(24, 68, 'Queue Jump', 8, 0, 0, 'don''t wait around in the cold, pay a few quid more and jump the queue!', '', ''),
(25, 77, 'vip', 60, 500, 10, 'ticket description', '', '{"0":"1"}'),
(26, 77, 'cheap tickets', 5, 0, 0, 'ticket description', '', '{"0":"1"}');
    enter code here
Was it helpful?

Solution

you could make a group-call in the sql-query, however it would be awkward to handle. In this case it's easier just to run through the results an extra time, like:

$available=array(); 
foreach($tickets as $ticket)
{ 
    if( !isset($available[$ticket->ide])) { $available[$ticket->ide]=true; }
    $available[$ticket->ide]=$available[$ticket->ide]?
    $ticket->seats > 0:$available[$ticket->ide]; 
}
// now like you said, only
foreach($tickets as $ticket)
{   
    if($available[$ticket->ide]){
        echo('Tickets available. ');
    }
    else{
        echo('Sold out. ');
    }
} 

Unless you have a really large number of events, it wount make much difference performance-wise, looping arrays like that is quick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top