Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Listing event name only once

Posted on 2008-09-30
23
Medium Priority
?
266 Views
Last Modified: 2013-12-12
I have a database where we have events entered. In one part of my website, I have it pulling up the next three ticketed events. In some cases, an event goes multiple dates and we only want it to show on the top 3 list once.
Example..
Event 1
Oct 2, 2008
Event 1
Oct 3, 2008
Event 1
Oct. 4, 2008

I want it to only list Event 1 one time and then the next two events that don't have the same Name as Event 1. Then when Oct. 3 comes around, oct 2 will drop off but the event will still be listed under Oct 3. When oct 4 is over, the event is still listed under oct 4.

The code is written below
<?php
	$currentdate = date('Y-m-D');
 
	$event_query = "SELECT * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' ORDER BY `Events`.`Date` ASC";
	$event_query_result = mysql_query($event_query);
 
	if (!event_query_result)
	{
		echo "Could not successfully run query ($event_query) from DB: " . mysql_error();
		exit;
	}
 
	$event_counter = 0;
 
	while ($event_row = mysql_fetch_assoc($event_query_result))
	{
		$event_name = $event_row['Name'];         
		$event_dates = $event_row['Date'];    
		$display_date = date("M j, Y", strtotime($event_dates ));        
		$event_time = $event_row['DisplayTime'];    
		$event_tickets = $event_row['Tickets'];        
		$event_id = $event_row['ID'];
		$eventCode = $event_row['EventCode'];
		$seasonCode = $event_row['SeasonCode'];
		$OnSale = $event_row['OnSale'];
 
		echo "<p class=\"style18\"><a href=\"display_event.php?id=$event_id\">$event_name</a> <br />\n";
		echo "$display_date - $event_time - <a href='http://ev12.evenue.net/cgi-bin/ncommerce3/SEGetEventInfo?ticketCode=GS%3ARUSHMORE%3A".$event_row['SeasonCode']."%3A".$event_row['EventCode']."%3A&linkID=rushmore&shopperContext=&caller=&appCode='>Click Here</a></p>\n";
 
		$event_counter++;
 
		if ($event_counter > 2)
		{
			break;
		}
	}
 
	if ($event_counter == 0)
	{
		echo "<p class=\"style18\">No Events Scheduled</p>\n";
	}	
?>

Open in new window

0
Comment
Question by:katlees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
  • 2
23 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 22610809
$event_query = "SELECT DISTINCT * FROM Events WHERE Date >= '$currentdate' ....
0
 

Author Comment

by:katlees
ID: 22610894
It's not working...
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22610989
SELECT DISTINCT * FROM Events WHERE Date >= `$currentdate` order by $currentdate Limit 0,2
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:ehabafia
ID: 22610994
The Limit will give you only the first 3 events.
 $event_query = "SELECT * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' ORDER BY `Events`.`Date` ASC limit 0,2";

Open in new window

0
 
LVL 28

Expert Comment

by:gamebits
ID: 22611004
Try this

SELECT *, count(Events) FROM Events WHERE Date >= '$currentdate' and Tickets ='1' GROUP BY Events HAVING count(Events)>=1 ORDER BY `Events`.`Date` ASC ";
0
 

Author Comment

by:katlees
ID: 22611013
ehabafia - that only shows the first two events..... and it lists two with the same nam.
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611019
$event_query = "SELECT DISTINCT * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' ORDER BY `Events`.`Date` ASC limit 0,3";
0
 

Author Comment

by:katlees
ID: 22611020
gamebits - that doesn't list any
0
 

Author Comment

by:katlees
ID: 22611027
It is still listing an event with the same name twice.....

Does it have to do with the event_counter being outside the loop?
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611033
SELECT DISTINCT(NAME), * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' ORDER BY `Events`.`Date` ASC limit 0,3
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611036
Sorry,

SELECT DISTINCT(NAME), * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' group by NAME ORDER BY `Events`.`Date` ASC limit 0,3
0
 

Author Comment

by:katlees
ID: 22611040
Ehabafia - again, no results
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611058
make sure that you have a result for the conditions that you are having,
also try to use the now() instead of current date:

SELECT DISTINCT(NAME), * FROM Events WHERE Date >= now() and Tickets ='1' group by NAME ORDER BY `Events`.`Date` ASC limit 0,3

I thing it should work
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611059
or currentdate()

SELECT DISTINCT(NAME), * FROM Events WHERE Date >= currentdate() and Tickets ='1' group by NAME ORDER BY `Events`.`Date` ASC limit 0,3
0
 

Author Comment

by:katlees
ID: 22611074
ehabafia - still getting no results. If I change my original code to
if ($event_counter > 7

It shows 7 results.... so I know there are records in there
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611279
could you send me a sample of the database data so that I can look at it.

Thank you and sorry for the delay.
0
 

Author Comment

by:katlees
ID: 22611309
http://75.125.62.3/~gotmine/index.php is the page it is on....

On http://75.125.62.3/~gotmine/index2.php I have it pulling the next 10 events
0
 

Author Comment

by:katlees
ID: 22611320
I got an answer from someone else. I'll post it in a minute
0
 

Accepted Solution

by:
katlees earned 0 total points
ID: 22611344
Here is the code
<?php
	$currentdate = date('Y-m-D');
 
	$event_query = "SELECT * FROM Events WHERE Date >= '$currentdate' and Tickets ='1' ORDER BY `Events`.`Date` ASC";
	$event_query_result = mysql_query($event_query);
 
	if (!event_query_result)
	{
		echo "Could not successfully run query ($event_query) from DB: " . mysql_error();
		exit;
	}
 
	$event_counter = 0;
	$save_event_name = "";
 
	while ($event_row = mysql_fetch_assoc($event_query_result))
	{
		$event_name = $event_row['Name'];         
		$event_dates = $event_row['Date'];    
		$display_date = date("M j, Y", strtotime($event_dates ));        
		$event_time = $event_row['DisplayTime'];    
		$event_tickets = $event_row['Tickets'];        
		$event_id = $event_row['ID'];
		$eventCode = $event_row['EventCode'];
		$seasonCode = $event_row['SeasonCode'];
		$OnSale = $event_row['OnSale'];
 
		if ($event_name != $save_event_name)
		{
			echo "<p class=\"style18\"><a href=\"display_event.php?id=$event_id\">$event_name</a> <br />\n";
			
			if (!(empty($eventCode)) && !(empty($seasonCode)))
			{
				echo "$display_date - $event_time - <a href='http://ev12.evenue.net/cgi-bin/ncommerce3/SEGetEventInfo?ticketCode=GS%3ARUSHMORE%3A".$event_row['SeasonCode']."%3A".$event_row['EventCode']."%3A&linkID=rushmore&shopperContext=&caller=&appCode='>Click Here</a></p>\n";
			}
			else
			{
				echo "$display_date - $event_time - <a href='#' onclick=\"javascript: DoTicketPopup();\" >Click Here</a></p>\n";
			}
			
			$save_event_name = $event_name;
			$event_counter++;
		}
 
		if ($event_counter > 2)
		{
			break;
		}
	}
 
	if ($event_counter == 0)
	{
		echo "<p class=\"style18\">No Events Scheduled</p>\n";
	}	
	
?>

Open in new window

0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611515
that's what I meant evenname (Event)  but I didn't know your database field names.

but you need to add at the ind of the sql statement the word Limit 0,3
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22611520
Well it was unfair to close the subject this way, without giving enough information but whatever.
0
 

Author Comment

by:katlees
ID: 22611593
I gave my full code. How is that not enough information? I got an answer elsewhere. Sorry yours didn't work.
0
 
LVL 4

Expert Comment

by:ehabafia
ID: 22613686
you gave the code but you didn't gave the database information.  Anyways I faced allot of peoples like you and that is not the first and it's not gonna be the last time facing someone like you.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question