dynamic url search links

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 8, 2012   (RSS)

By markr - March 7, 2012

I was looking to create url search links based on the month of the event. Easy enough...

E.g. /listpage.php?event_month=4

But I didn't want 12 static links (one for each month) if my events only went out a few months.

Just wanted to share my query and loop with the forum:

$result = mysql_query("SELECT DISTINCT MONTH(event) AS `Month` FROM `cms_games` WHERE `event` > NOW() ORDER BY `event` ASC");

while($row = mysql_fetch_array($result)) {
$monthName = date("F", mktime(0, 0, 0, $row['Month']));
$monthNumber = date("m", mktime(0, 0, 0, $row['Month']));
echo "<a href ='listpage.php?event_month=".$monthNumber."'>".$monthName."</a>";
} // end while

Re: [markr] dynamic url search links

By Jason - March 8, 2012

Hi,

Thanks for posting. That's a great alternative to having to hard code in values.

An easy alternative to using mktime is to use the PHP strtotime function, where you can take in an entire date string and remove only the pieces that you want. For example:

$monthNumber = date("m", strtotime($row['event']));

Thanks again for sharing your solution!
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/