Avatar of Johnny
JohnnyFlag for United States of America

asked on 

how to print list out of each event days from today forward

i have a event listing that works great for today, in that it looks for the start and end fields info and if today falls inside that range it prints it out for todays date. that works wonderfully.
how do i get tomorrow and all the rest of the dates to print out with date as the heading of the section ie

9/2/13 Monday
event title 1
event title 2
event title 6
9/3/13 Tuesday
event title 3
event title 4
event title 12
9/4/13 wed
etc

here is my code so far
<?php
include ('ctx.php');

//
// 
//$result = mysqli_query($con,"select * from iwia_events where event_start < now() and event_end > DATE_ADD(DATE(now()), INTERVAL 11 MONTH)");
//$sql="select * from iwia_events WHERE event_start BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)";
$sql="select * from iwia_events where event_start <= now() and event_end >= now()";
//$sql="select * from iwia_events where event_start < DATE_ADD(CURDATE(), INTERVAL -1 DAY) and event_end > CURDATE()";
//$sql="SELECT * FROM iwia_events WHERE event_start BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND event_end > CURDATE()";

$result = mysqli_query($con,$sql);


if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
echo "<strong style='color:black;'>".date('l jS \of F')."</strong><br>";
while($row = mysqli_fetch_array($result))
  {
  $start_event=date('m-d-Y', strtotime($row['event_start'])); 
  $end_event=date('m-d-Y', strtotime($row['event_end']));     
if ($row['active'] == "1") {
    
  echo '<IMG SRC="'.$row['event_image'].'" ALT="?" BORDER=0 style="width:90px; height:90px;" align="left"></div><br>';
  //echo "Location: ".$row['event_location']."<br>";
  if ($row['event_location']) {
      $loc = "Location: ".$row['event_location']."";
  }
  else {
      $loc="";
  }
  echo " &nbsp;<A HREF='single_event.php?id=".$row['id']."' title=\"".$loc."\">".$row['event_title'] . "</a> <br>";
  
  
  echo "<span style='font-size: 10px; color: gray;'>&nbsp; Start: " . $start_event ." - End: ".$end_event."</span>";
  echo "<p>&nbsp;</p>";
  }
}  
if (!mysqli_num_rows($result)) {
	echo "No Events for today<br>";
}

mysqli_close($con);
?>

Open in new window


note: i tried in the $sql = to do some testing but non worked. and i couldn't figure out how to do the days heading from the search.

Thank you in advance for any code or help you may provide.
PHPMySQL Server

Avatar of undefined
Last Comment
Ray Paseur
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

ok well i rewrote the mysqli routines
/// OPEN A CONNECTION TO THE DATA BASE SERVER AND SELECT THE DB
$mysqli = new mysqli($db_host, $db_user, $db_word, $db_name);

// DID THE CONNECT/SELECT WORK OR FAIL?
if ($mysqli->connect_errno)
{
    $err
    = "CONNECT FAIL: "
    . $mysqli->connect_errno
    . ' '
    . $mysqli->connect_error
    ;
    trigger_error($err, E_USER_ERROR);
}
// SHOW WHAT THE DB CONNECTION OBJECT LOOKS LIKE
/*
echo "<pre>";
var_dump($mysqli);
echo "</pre>";
*/

Open in new window


<?php
echo 'Showing events for: : ' . $_SESSION['subdomain'] . '<br>';
$pieces = explode("-", $_SESSION['subdomain']);
$subdomain_city =strtolower($pieces[0]);
$subdomain_state=strtolower($pieces[1]);
//echo $subdomain_state;
include ('mysqli_ctx.php');

// event_location
// 
//$result = mysqli_query($con,"select * from iwia_events where event_start < now() and event_end > DATE_ADD(DATE(now()), INTERVAL 11 MONTH)");
//$sql="select * from iwia_events WHERE event_start BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)";
$sql="select * from iwia_events where event_start <= now() and event_end >= now() AND `event_location` LIKE LOWER('%$subdomain_city%') AND `event_location` LIKE LOWER('%$subdomain_state%')";
//$sql="select * from iwia_events where event_start < DATE_ADD(CURDATE(), INTERVAL -1 DAY) and event_end > CURDATE()";
//$sql="SELECT * FROM iwia_events WHERE event_start BETWEEN DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND event_end > CURDATE()";

$res = $mysqli->query($sql);

// IF mysqli_query() RETURNS FALSE, LOG AND SHOW THE ERROR
if (!$res)
{
    $err
    = "QUERY FAIL: "
    . $sql
    . ' ERRNO: '
    . $mysqli->errno
    . ' ERROR: '
    . $mysqli->error
    ;
    trigger_error($err, E_USER_ERROR);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESULT OBJECT IN $res
// AND SO WE CAN NOW USE $res IN OTHER MYSQLI FUNCTIONS

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $res->num_rows;
$num_fmt = number_format($num);
if (!$num)
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>No Events for today<br> ";
    echo PHP_EOL;
}
else
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt Events <br/>";
    echo PHP_EOL;
}



echo "<strong style='color:black;'>".date('l jS \of F')."</strong><br>";
while ($row = $res->fetch_array())
{
  $start_event=date('m-d-Y', strtotime($row['event_start'])); 
  $end_event=date('m-d-Y', strtotime($row['event_end']));     
if ($row['active'] == "1") {
    
  echo '<IMG SRC="'.$row['event_image'].'" ALT="?" BORDER=0 style="width:90px; height:90px;" align="left"></div><br>';
  //echo "Location: ".$row['event_location']."<br>";
  if ($row['event_location']) {
      $loc = "Location: ".$row['event_location']."";
  }
  else {
      $loc="";
  }
  echo " &nbsp;<A HREF='single_event.php?id=".$row['id']."' title=\"".$loc."\">".$row['event_title'] . "</a> <br>";
  
  
  echo "<span style='font-size: 10px; color: gray;'>&nbsp; Start: " . $start_event ." - End: ".$end_event."</span>";
  echo "<p>&nbsp;</p>";
  }
}
  

mysqli_close($mysqli);
?>

Open in new window


it seams to be correct now ** i have been wanting to make functions and add a mysqli_functions.php file to project instead of looking up the routines each time. i never came across one yet, not looking forward to making one but i should find one or make one soon. I do like Mysqli better it seems to have more it can do. thank you as always

on to date time suggestions
Practical Application #12 seams close to what im trying to do. (i didnt see it pop out at me for any help tho on my current display issue)
i still think im beating my head against the wall (im not sure if you remeber i was trying to work on adding stringtotime parsed dates to mysql for events.) i finally got that to work. but each day is counted as a entry(database fills up really fast for recurring dates) im also finding events are really hard to do(code wise).
but lets try and get this solved and maybe ill ask how i SHOULD be doing this as recurring events(if they can't be melded)
heres my current create event info
CREATE TABLE IF NOT EXISTS `iwia_events` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `event_title` varchar(255) NOT NULL DEFAULT '',
  `event_location` varchar(255) DEFAULT NULL,
  `event_price` varchar(20) DEFAULT NULL,
  `event_image` varchar(255) DEFAULT 'http://XXXXXX.com/default-event-avatar.png',
  `event_url` varchar(200) DEFAULT NULL,
  `event_start` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `event_end` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `event_text` text,
  `extra_info` text,
  `facebook` enum('0','1') NOT NULL DEFAULT '0',
  `twitter` enum('0','1') NOT NULL DEFAULT '0',
  `active` enum('0','1') NOT NULL DEFAULT '1',
  `categories` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=186 ;

Open in new window

im fully open to changing what ever needs to be changed and i am by all means willing to admit im not doing this correctly or there a better way. again thank you for any help
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Your table structure looks OK to me.  Perhaps the query is not exactly what you want, or perhaps the INSERT process is putting too much information into the table.

Consider an event that starts 2013-09-02 15:00:00 and ends 2013-09-02 18:00:00.  That would represent one row in the data base table.

Now have a look at this code, which I cannot test because I don't have any test data.  This does not represent a finished piece of work, but it should be OK for proof of concept.  The SELECT query seems to be saying, give me anything that ever started at any time in the past and that will end at any time in the future if it has active=1 and matches on city and state.  To me that kind of sounds like "What's happening here now?"

Does that make sense to you?

<?php
error_reporting(E_ALL);

echo 'Showing events for: : ' . $_SESSION['subdomain'] . '<br>';
$pieces = explode("-", $_SESSION['subdomain']);
$subdomain_city =strtolower($pieces[0]);
$subdomain_state=strtolower($pieces[1]);
//echo $subdomain_state;
include ('mysqli_ctx.php');

$sql="SELECT * FROM iwia_events WHERE event_start <= NOW() and event_end >= NOW() AND active = '1' AND `event_location` LIKE LOWER('%$subdomain_city%') AND `event_location` LIKE LOWER('%$subdomain_state%')";
if (!$res = $mysqli->query($sql))
{
    $err
    = "QUERY FAIL: "
    . $sql
    . ' ERRNO: '
    . $mysqli->errno
    . ' ERROR: '
    . $mysqli->error
    ;
    trigger_error($err, E_USER_ERROR);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESULT OBJECT IN $res
// AND SO WE CAN NOW USE $res IN OTHER MYSQLI FUNCTIONS

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $res->num_rows;
$num_fmt = number_format($num);
if (!$num)
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>No Events for today<br> ";
    echo PHP_EOL;
}
else
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt Events <br/>";
    echo PHP_EOL;
}



echo "<strong style='color:black;'>".date('l jS \o\f F')."</strong><br>";
echo '<pre>';
while ($row = $res->fetch_object())
{
    print_r($row);
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

@ Ray_Paseur yes but with more here i also need to print it out in blocks like this
http://chicagoil.iswhereitsat.com/
in the middle is the events all listing by days, i need my list to start for today
and return all dates in the future in each days block.
i never thought of searching as a where instead of pulling them all for active (thanks)

test data: some of it...im trying now to get rid of the utf-8 characters and ones like ’ for ' i just noticed are happening, doing research on how to do that so sorry some entries have them in this sample code(some are from rss/ical/atom feeds) again driving me nuts *sorry*
INSERT INTO `iwia_events` (`id`, `event_title`, `event_location`, `event_price`, `event_image`, `event_url`, `event_start`, `event_end`, `event_text`, `extra_info`, `facebook`, `twitter`, `active`, `categories`) VALUES
(1, 'Metal Machine Monday- Upstairs at EXIT', 'Exit\r\n1315 W North Ave\r\nChicago, IL, 60642-1513', 'Free', 'https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-prn1/c268.0.315.315/s552x414/560827_10151619336171173_851548175_n.jpg', '', '2013-08-26 22:00:00', '2013-08-27 04:00:00', 'Mondays are a celebration of the rhythm of machines at work upstairs at EXIT. Walls of distortion, driven by drums. An eclectic mix of MusicK from the most current sounds in Death Disco to digital rockstars awash in the history of analog warmth.\r\n\r\nIndustrial/EBM/Goth/Metal\r\n\r\nEBM or metal? Let your body decide. Your reaction steers this ship into space or into the bowels of Hades. If you dance you will receive dance music, if not we will supply the other side of the coin.\r\n\r\nResident Djs Restriction & Peter Propaganda will be joined weekly by guest djs and an assortment of surprise guests performers and freaks they call friends\r\n\r\nXtina will be behind the bar mixing her specialty drinks like the “Machine Sex” for your consumption…', NULL, '0', '0', '1', 'DJ''S / DANCING'),
(2, '50 cent Boneless Wings', 'Wing Stop\r\n3326 North Western Avenue\r\nRiverview Plaza, Chicago, IL 60618', NULL, 'http://chicagoil.iswhereitsat.com/wp-content/themes-ai1ec/vortex/img/default-event-avatar.png', '', '2013-08-27 11:00:00', '2013-08-27 22:00:00', 'Date: Every Tuesday!\r\nTime: 11a.m. – 10p.m.\r\nPlace: Wing Stop\r\n\r\nAll varieties of wings are only 50 cents on Monday and Tuesday!', NULL, '0', '0', '1', 'FOOD SPECIALS'),
(3, 'Lincoln Park Zoo’s Edible Garden', 'Farm In The Zoo\r\n2001 North Clark Street\r\nChicago, IL 60614', 'Free', 'http://chicagoil.iswhereitsat.com/wp-content/uploads/sites/10/2013/06/edible-garden2.jpg', '', '2013-08-27 10:00:00', '2013-11-01 13:00:00', 'Learn Where Your Food Comes From!\r\nThe Edible Garden, located in the Farm-in-the-Zoo and planted and maintained by Chicago’s Green City Market, lets kids experience hands-on lessons on the origins of food. Family visits and field trips offer the opportunity to plant, weed, compost and harvest, establishing a deeper connection to the resources that sustain us all.\r\n\r\nThe seasonal “green thumb” fun includes planting tomatoes, pulling weeds, thinning carrots, harvesting green beans and digging purple potatoes. It’s an inclusive harvest—the Edible Garden is designed to accommodate children with disabilities.', NULL, '0', '0', '1', 'FAMILY FUN, HEALTH & FITNESS, NATURE & WILDLIFE'),
(4, 'Happy Hour at Frankie’s 5th Floor Pizzeria', 'Frankie''s 5th Floor Pizzeria\r\n900 North Michigan\r\nChicago, IL 60611', NULL, 'http://chicagoil.iswhereitsat.com/wp-content/themes-ai1ec/vortex/img/default-event-avatar.png', 'http://http//www.shop900.com/events/462/', '2013-08-27 15:00:00', '2013-10-31 18:00:00', 'Looking for a great spot to bring your co-workers for an early evening beverage or a place to meet a friend for appetizers and cocktails? Well, Frankie’s new ‘Happy Hour Specials’ are here!  Frankie’s offers bar plates priced at $1-$5, including homemade meatballs, calamari pepperonata, roasted chicken thighs and so much more.  Daily ‘Drink Specials’ for as low as $5.', 'CONTACT:\r\n(312) 266-2500', '0', '0', '1', 'DRINK SPECIALS, RETAIL SALES'),
(5, 'Socrates Party', '709 S Randolph St Champaign, IL 61820', '25', 'http://chicagoil.iswhereitsat.com/wp-content/themes-ai1ec/vortex/img/default-event-avatar.png', '', '2013-08-30 22:44:00', '2013-09-28 22:44:00', 'This is the party for having a system that works', 'We will be committing crimes against nature :)', '0', '0', '1', 'party, DJ, rave'),
(6, 'NASCAR Contenders Live', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-09-01 18:00:00', '2013-09-12 20:00:00', 'Back by popular demand\\, NASCAR Contenders LiveSM Sponsored byToyota will make its return to Chicago on September 12 for the second-consecutive year\\, just days before the first race of the 2013 Chase for the NASCAR Sprint Cup™ at Chicago land Speedway. Signaling the start of the most intense and competitive stretch of the NASCAR season\\, NASCAR Contenders Live features all 12 Chase for the NASCAR Sprint Cup drivers interacting on stage\\, providing fans an insider’s look at how the competitors plan to claim', 'Location: Grand Ballroom<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(7, 'Countdown to the Centennial', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-09-21 00:00:00', '2013-09-22 00:00:00', 'Doors open at 5 p.m.\\nCountdown to the Centennial is a community celebration with free services\\, an interactive art and photo exhibit\\,a biblical presentation for enlightenment\\, hope and happiness\\, and a liveshowcase of original Christian music to inspire and delight the soul. For', 'Location: Grand Ballroom<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(8, 'The Doc McStuffins Mobile', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-25 14:00:00', '2013-08-25 21:00:00', 'Join Disney Junior at The Doc Mobile for a family-fun event focused on healthy living as kids see “there’s so much you can do to take careof you!”  They’ll be moving & shaking along to their favorite Doc songs with Radio Disney Junior\\, and experiencing activities showing them how to make a healthy plate and the importance of drinking enough water.  Be sure tobring a toy so kids can be just like Doc and give their toy a check-up inside Doc’s clinic! Doc’s got just the right diagnosis that makes staying healthy and doctor visits so much fun for your little one!\\n \\nAlso\\, StartingFriday\\, September 6\\, your little one can see new episodes of Doc McStuffins every Friday all month long on Disney Junior\\, on Disney Channel! The premiere episode features Doc’s new mobile clinic so she can help toys on-th', 'Location: Compass Rose<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(9, 'BIGMINI', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-05 00:00:00', '2013-08-12 00:00:00', 'Our garden is in full bloom – with the bigger\\, 4-door MINI Countryman\\, that is. Come down to Navy Pier’s Pier Park to check out the BIGMINI in all its natural glory today. Who knows? It may even grow before youreyes.', 'Location: Pier Park<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(10, 'SOFA CHICAGO 2013', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-10-31 00:00:00', '2013-11-04 00:00:00', 'The 20th Annual Exposition of Sculpture Objects and FunctionalArt Fair is a gallery-presented\\, international art exposition dedicated tobridging the worlds of design\\, decorative and fine art. Works by emergingand established artists and designers are available for sale by premier ga', 'Location: Festival Hall<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(11, 'Shoreline Sightseeing Oktoberfest Cruise', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-09-28 00:00:00', '2013-09-28 02:00:00', 'Two-hour cruise with German dinner including brats from PaulinaMarket\\, free drink in a souvenir mug and German music. Cash bar available', 'Location: Gateway Park at Navy Pier<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(12, 'Texas on Tour', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-18 16:00:00', '2013-08-18 23:00:00', 'Texas Tourism has rolled into Chicago this weekend! Come out toNavy Pier and experience Texas on Tour\\, an all-new experiential exhibit that gives potential travelers a taste of the fun and adventure the Lone Star State has to offer.\\n \\nThe exhibit virtually transports participants to', 'Location: Gateway Park<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(13, 'Texas on Tour', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-17 16:00:00', '2013-08-18 02:00:00', 'Texas Tourism has rolled into Chicago this weekend! Come out toNavy Pier and experience Texas on Tour\\, an all-new experiential exhibit that gives potential travelers a taste of the fun and adventure the Lone Star State has to offer.\\n \\nThe exhibit virtually transports participants to', 'Location: Gateway Park<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(14, 'Texas on Tour', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-16 17:00:00', '2013-08-17 01:00:00', 'Texas Tourism has rolled into Chicago this weekend! Come out toNavy Pier and experience Texas on Tour\\, an all-new experiential exhibit that gives potential travelers a taste of the fun and adventure the Lone Star State has to offer.\\n \\nThe exhibit virtually transports participants to', 'Location: Gateway Park<br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(15, 'Shoreline Water Taxi Transfers for Taylor Swift Concert at SoldierField', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-08-10 00:00:00', '2013-08-11 00:00:00', 'Shoreline Water Taxi Transfers are available for round trip transportation from Navy Pier to Museum Campus/Soldier Field for the Taylor Sw', 'Location: <br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event'),
(16, 'Shoreline Sightseeing Wine Tasting Cruise', 'Navy Pier, Inc 600 E Grand Ave, Chicago, IL 60611', NULL, 'http://blog.navypier.com/wp-content/uploads/headway/header-uploads/navy-blog2_08.png', 'http://blog.navypier.com', '2013-09-12 00:00:00', '2013-09-13 00:00:00', 'Featuring wines of Chicago-area Lynfred Winery plus light refreshments and a ninety-minute cruise on Shoreline''s climate controlled "Celeb', 'Location: <br>Navy Pier, Inc <br>600 E Grand Ave, Chicago, IL 60611<br>Phone: (312) 595-7437', '0', '0', '1', 'Navy Pier Event');

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

fyi your return
Showing events for: : chicago-il

FOUND 3 Events 
Monday 2nd of September
stdClass Object
(
    [id] => 3
    [event_title] => Lincoln Park Zoo’s Edible Garden
    [event_location] => Farm In The Zoo
2001 North Clark Street
Chicago, IL 60614
    [event_price] => Free
    [event_image] => http://chicagoil.iswhereitsat.com/wp-content/uploads/sites/10/2013/06/edible-garden2.jpg
    [event_url] => 
    [event_start] => 2013-08-27 10:00:00
    [event_end] => 2013-11-01 13:00:00
    [event_text] => Learn Where Your Food Comes From!
The Edible Garden, located in the Farm-in-the-Zoo and planted and maintained by Chicago’s Green City Market, lets kids experience hands-on lessons on the origins of food. Family visits and field trips offer the opportunity to plant, weed, compost and harvest, establishing a deeper connection to the resources that sustain us all.

The seasonal “green thumb” fun includes planting tomatoes, pulling weeds, thinning carrots, harvesting green beans and digging purple potatoes. It’s an inclusive harvest—the Edible Garden is designed to accommodate children with disabilities.
    [extra_info] => 
    [facebook] => 0
    [twitter] => 0
    [active] => 1
    [categories] => FAMILY FUN, HEALTH & FITNESS, NATURE & WILDLIFE
)
stdClass Object
(
    [id] => 4
    [event_title] => Happy Hour at Frankie’s 5th Floor Pizzeria
    [event_location] => Frankie's 5th Floor Pizzeria
900 North Michigan
Chicago, IL 60611
    [event_price] => 
    [event_image] => http://chicagoil.iswhereitsat.com/wp-content/themes-ai1ec/vortex/img/default-event-avatar.png
    [event_url] => http://http//www.shop900.com/events/462/
    [event_start] => 2013-08-27 15:00:00
    [event_end] => 2013-10-31 18:00:00
    [event_text] => Looking for a great spot to bring your co-workers for an early evening beverage or a place to meet a friend for appetizers and cocktails? Well, Frankie’s new ‘Happy Hour Specials’ are here!  Frankie’s offers bar plates priced at $1-$5, including homemade meatballs, calamari pepperonata, roasted chicken thighs and so much more.  Daily ‘Drink Specials’ for as low as $5.
    [extra_info] => CONTACT:
(312) 266-2500
    [facebook] => 0
    [twitter] => 0
    [active] => 1
    [categories] => DRINK SPECIALS, RETAIL SALES
)
stdClass Object
(
    [id] => 63
    [event_title] => A Month Of Storytelling Open Mic
    [event_location] => Chicago, IL 60611
    [event_price] => 
    [event_image] => http://gapersblock.com/gfx/gapersblock_250x250.jpg
    [event_url] => http://gapersblock.com
    [event_start] => 2013-09-02 01:30:00
    [event_end] => 2013-12-12 01:30:00
    [event_text] => A Month Of is a new monthly, open-mic storytelling series where the audience selects the event's theme online before the show starts. Open mic slots are 5-7 minutes long, all story types and forms are welcome. The show is every...
    [extra_info] => 
    [facebook] => 0
    [twitter] => 0
    [active] => 1
    [categories] => Gapers Block Slowdown Event
)

Open in new window


this returns exactly what i have but in a much better way thank you.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

would i do something like a php loop and make the sql like this would that work
for ($i = 1; $i <= {how would we stop, can we capture end of year maybe}; $i++) {

$sql="SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL $i DAY) AND event_end >= (now() + INTERVAL &i DAY) AND active = '1' AND `event_location` LIKE LOWER('%$subdomain_city%') AND `event_location` LIKE LOWER('%$subdomain_state%')";

echo "<strong style='color:black;'>".date('l jS \of F',strtotime('+$i day'))."</strong><br>";

// do event data output block

}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

for till end of year?
$datetime1 = date_create('now');
$datetime2 = date_create('2014-01-01');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days');
// $interval = how many days?
$days_till_end_of_year =  $interval->format('%a');

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Wow, there are so many moving parts here I almost don't know what to do first!  Maybe consider changing your character set to UTF-8 throughout.  The whole world is going that way.  This article will give you some pointers about the conversion.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html

I'll try to take a look at the other issues tomorrow.  Best regards, ~rAY
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

i fixed the utf-8 problem (that i saw when i printed the table data.
$event['DESCRIPTION'] = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $event['DESCRIPTION']);

Open in new window

thank you i shoulda known you would have a page too
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Still trying to get my head around exactly what you want to get from the data base.  If you want to use the date values in a query, this sort of structure often works well.

$now = date('c');
$sql = "SELECT cols FROM tables WHERE '$now' BETWEEN event_start AND event_end";

What that is saying is take the current date in ISO-8601 format and use it in the BETWEEN sub-clause of the WHERE clause of the query.  Anything that is happening today will be returned.  If you choose another date, that's fine, too.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

@ Ray_Paseur i'm trying to print a listing of UPCOMING events, the code i have works great for single "today" im trying to get a list of next day and the fallowing day etc as a list.
i had a problem because it needs to fall within the range of the day its pulling the data.
if you look at the listing at http://chicagoil.iswhereitsat.com/ looking at the upcomming events listing i want to do somethign simaler. but with today as the start heading and then continue on with next days heading then list and next days heading and list (see example at first post)
what part are you having a problem following ive said this 3 times now please ask me direct questions of what your not understanding i need done.

and would my example work? with the $i loop then. (*smile* i guess i could plug it in right and see - duh!)
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

well this kinda works or seams to
it needs to be unique output for one.
and the date heading is wrong(my guess on strtotime didnt work i guess)
i am by all means nor sure this is the right way at all(and page will have to be added at one point as thats way to big a list to output too)
its my attempt to guess, hence the reason for this post, i am unsure how to do this.
but heres my code
<?
session_start();
//****************************************************************
// Filename..: __.php
// Author....: __
// Date......: mm/dd/yyyy
// Purpose...: __
// SQL.......: server/database/tables/tablename
//****************************************************************
// include("filename.php");
include ('mysqli_ctx.php');
include("iwia_location_subdomain.php");
echo 'Showing events for: : ' . $_SESSION['subdomain'] . '<br>';

$pieces = explode("-", $_SESSION['subdomain']);
$subdomain_city =strtolower($pieces[0]);
$subdomain_state=strtolower($pieces[1]);
//echo $subdomain_state;

$datetime1 = date_create('now');
$datetime2 = date_create('2014-01-01');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days')."<br>";
// $interval = how many days?
$days_till_end_of_year =  $interval->format('%a');


for ($i = 1; $i <= $days_till_end_of_year; $i++) {

$sql="SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL $i DAY) AND event_end >= (now() + INTERVAL $i DAY) AND active = '1' AND `event_location` LIKE LOWER('%$subdomain_city%') AND `event_location` LIKE LOWER('%$subdomain_state%')";
echo"sql: ".$sql."<br>";
echo "<strong style='color:black;'>".date('l jS \of F',strtotime('+$i day'))."</strong><br>";

$res = $mysqli->query($sql);

// IF mysqli_query() RETURNS FALSE, LOG AND SHOW THE ERROR
if (!$res)
{
    $err
    = "QUERY FAIL: "
    . $sql
    . '<br> ERRNO: '
    . $mysqli->errno
    . '<br> ERROR: '
    . $mysqli->error
    ;
    trigger_error($err, E_USER_ERROR);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESULT OBJECT IN $res
// AND SO WE CAN NOW USE $res IN OTHER MYSQLI FUNCTIONS

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $res->num_rows;
$num_fmt = number_format($num);
if (!$num)
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>No Events for today<br> ";
    echo PHP_EOL;
}
else
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt Events <br/>";
    echo PHP_EOL;
}

// do event data output block
while ($row = $res->fetch_array())
{
  $start_event=date('m-d-Y', strtotime($row['event_start'])); 
  $end_event=date('m-d-Y', strtotime($row['event_end']));     
if ($row['active'] == "1") {
    
  echo '<IMG SRC="'.$row['event_image'].'" ALT="?" BORDER=0 style="width:90px; height:90px;" align="left"></div><br>';
  //echo "Location: ".$row['event_location']."<br>";
  if ($row['event_location']) {
      $loc = "Location: ".$row['event_location']."";
  }
  else {
      $loc="";
  }
  echo " &nbsp;<A HREF='single_event.php?id=".$row['id']."' title=\"".$loc."\">".$row['event_title'] . "</a> <br>";
  
  
  echo "<span style='font-size: 10px; color: gray;'>&nbsp; Start: " . $start_event ." - End: ".$end_event."</span>";
  echo "<p>&nbsp;</p>";
  }
}
  
}
mysqli_close($mysqli);
?>

Open in new window


output first few returns returns... (note ? are the images)
-----------------------------------------------------------------
Showing events for: : chicago-il
+119 days
sql: SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL 1 DAY) AND event_end >= (now() + INTERVAL 1 DAY) AND active = '1' AND `event_location` LIKE LOWER('%chicago%') AND `event_location` LIKE LOWER('%il%')
Wednesday 31st of December

FOUND 3 Events
?
 Lincoln Park Zoo’s Edible Garden
  Start: 08-27-2013 - End: 11-01-2013
 

?
 Happy Hour at Frankie’s 5th Floor Pizzeria
  Start: 08-27-2013 - End: 10-31-2013
 

?
 A Month Of Storytelling Open Mic
  Start: 09-02-2013 - End: 12-12-2013
 

sql: SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL 2 DAY) AND event_end >= (now() + INTERVAL 2 DAY) AND active = '1' AND `event_location` LIKE LOWER('%chicago%') AND `event_location` LIKE LOWER('%il%')
Wednesday 31st of December

FOUND 3 Events
?
 Lincoln Park Zoo’s Edible Garden
  Start: 08-27-2013 - End: 11-01-2013
 

?
 Happy Hour at Frankie’s 5th Floor Pizzeria
  Start: 08-27-2013 - End: 10-31-2013
 

?
 A Month Of Storytelling Open Mic
  Start: 09-02-2013 - End: 12-12-2013
 

sql: SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL 3 DAY) AND event_end >= (now() + INTERVAL 3 DAY) AND active = '1' AND `event_location` LIKE LOWER('%chicago%') AND `event_location` LIKE LOWER('%il%')
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

@Ray_Paseur regarding ID: 39461104
that output seems to work great as a list.
but i need day headings. this seems to be getting really close
i also cant believe there still even more to all this event things then i even realized, and i have learned more in this page then i think i have in 2 years messing with this.
thank you as always
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

is this the right way to do it, it seems to work (if i get the list to work right it should repeat each event for each day right, or am i missing something?)

<?
session_start();
//****************************************************************
// Filename..: __.php
// Author....: __
// Date......: mm/dd/yyyy
// Purpose...: __
// SQL.......: server/database/tables/tablename
//****************************************************************
// include("filename.php");
include ('mysqli_ctx.php');
include("iwia_location_subdomain.php");
echo 'Showing events for: : ' . $_SESSION['subdomain'] . '<br>';

$pieces = explode("-", $_SESSION['subdomain']);
$subdomain_city =strtolower($pieces[0]);
$subdomain_state=strtolower($pieces[1]);
//echo $subdomain_state;

$datetime1 = date_create('now');
$datetime2 = date_create('2014-01-01');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days')."<br>";
// $interval = how many days?
$days_till_end_of_year =  $interval->format('%a');

$today = date('c');
$cutoff = date('c', strtotime('2014-01-01'));
//SELECT cols FROM tables WHERE (event_start < '$cutoff') AND (event_start >= '$today' OR event_end >= '$today') ORDER BY event_start

for ($i = 1; $i <= $days_till_end_of_year; $i++) {

$sql="SELECT * FROM iwia_events WHERE event_start <= (now() + INTERVAL $i DAY) AND event_end >= (now() + INTERVAL $i DAY) AND active = '1' AND `event_location` LIKE LOWER('%$subdomain_city%') AND `event_location` LIKE LOWER('%$subdomain_state%')";
//echo"sql: ".$sql."<br>";
// replace time() with the time stamp you want to add one day to
$startDate = time();
$day_plus="+".$i." day";
echo "<strong style='color:black;'>".date('l jS \of F', strtotime($day_plus, $startDate))."</strong><br>";

$res = $mysqli->query($sql);

// IF mysqli_query() RETURNS FALSE, LOG AND SHOW THE ERROR
if (!$res)
{
    $err
    = "QUERY FAIL: "
    . $sql
    . '<br> ERRNO: '
    . $mysqli->errno
    . '<br> ERROR: '
    . $mysqli->error
    ;
    trigger_error($err, E_USER_ERROR);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESULT OBJECT IN $res
// AND SO WE CAN NOW USE $res IN OTHER MYSQLI FUNCTIONS

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $res->num_rows;
$num_fmt = number_format($num);
if (!$num)
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>No Events for today<br> ";
    echo PHP_EOL;
}
else
{
    //echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt Events <br/>";
    echo PHP_EOL;
}

// do event data output block
while ($row = $res->fetch_array())
{
  $start_event=date('m-d-Y', strtotime($row['event_start'])); 
  $end_event=date('m-d-Y', strtotime($row['event_end']));     
if ($row['active'] == "1") {
    
  echo '<IMG SRC="'.$row['event_image'].'" ALT="event_image" BORDER=0 style="width:90px; height:90px;" align="left"></div><br>';
  //echo "Location: ".$row['event_location']."<br>";
  if ($row['event_location']) {
      $loc = "Location: ".$row['event_location']."";
  }
  else {
      $loc="";
  }
  echo " &nbsp;<A HREF='single_event.php?id=".$row['id']."' title=\"".$loc."\">".$row['event_title'] . "</a> <br>";
  
  
  echo "<span style='font-size: 10px; color: gray;'>&nbsp; Start: " . $start_event ." - End: ".$end_event."</span>";
  echo "<p>&nbsp;</p>";
  }
}
  
}
mysqli_close($mysqli);
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

image of output so far
http://prntscr.com/1p4vke
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

pleasure as always ray, it amazes me each time and i learn a lot when you post things. thank you
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Glad you've got it sorted out -- I've been away most of today.  Thanks for the points and for your kind words, ~Ray
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

any time you need a puffed chest or a metal ask me ill be happy to provide the words and compliments.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Ha!  Thanks, and thanks for using EE, ~Ray
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo