Grow your CSS skills. Land your dream job.

php gig list not ordering AM-PM correctly

  • # November 2, 2011 at 2:11 pm

    Unfortunately, I have not yet learned PHP. (working on javascript at the moment)

    I am hoping someone can point me in the right direction to correct this problem.

    I am using a wordpress plugin called “gigs calendar”. It lists gig dates for bands. It is not really supported though I have posted the issue on the authors site. You can find the plugin page here http://wordpress.org/extend/plugins/gigs-calendar/

    You can see my install here. http://thishope.org/schedule/?page_id=5

    You will notice that the two events on Nov 20 are not listed in the correct order (PM comes first). It does not matter how I enter them, they always list like this.

    I don’t even know which part of the code to post along with this question.

    I am hoping someone can get me started on what to look for or which part of the code to post here for eveluation.

    Thanks in advance.

    # November 5, 2011 at 7:21 am

    The first thing you need to do is to look in the database to see what format the date/time is in.

    Then we can look at adapting the SQL query.

    # February 13, 2012 at 4:45 pm

    @lyleyboy – How do I look in the database and where do I look?

    # February 13, 2012 at 4:52 pm

    Wait… I found a “tables.sql” in the folder for the plugin.

    Oped it and it says “time default NULL” in the “time” code.

    Is that what you are looking for?

    # February 13, 2012 at 7:07 pm

    that file is just the file that creates the tables presumably, the time default NULL just means the time field will be blank by default.

    What you are looking for the query lines some of which are found inside gigs-classes.php (i haven’t looked through all the other files)

    At line 303 you find a query being built inside the search() function



    $this->_rows = $this->wpdb->get_results('SELECT * FROM `' . $this->_table . '` ' . ($where !== null ? 'WHERE ' . $where : '') . ($order !== null ? ' ORDER BY ' . $order : ''));

    This query is ordering the results by whatever the $order specifies, a variable passed to the order function.

    The getPerformances() function for example is passing time as the $order


    function getPerformances() {
    $p = new performance();
    if ( $this->id ) {
    $p->search("`gigID` = " . (int) $this->id, "`time`");
    }
    return $p;
    }

    I can’t access your site right now to look as it appears to be a little broken, maybe its just as simple as reversing the order from ASC to DESC, are the times unordered or in the wrong order?

    # February 13, 2012 at 9:13 pm

    @bungle – Thanks for looking at this for me. I found the file and the query. Not sure how to address it. I can’t find ASC or DESC.

    The page is up for me now. Not sure what was wrong. http://thishope.org/schedule/

    I have three events posted. The first two posted in correct order am to pm. The next two do not (pm-am)

    They are ordered correctly by date but the time of day does not seem to order them. Do I need to add something to make this happen?

    # February 13, 2012 at 10:38 pm

    The problem may be that it isn’t specifying ASC or DESC so it’s returning in no specific order. Give me an hour or two and I’ll take a look at it again.

    # February 13, 2012 at 10:51 pm

    Worse yet it may not be storing time in a sortable format rather as a string. I’ll take a look.

    # February 13, 2012 at 11:37 pm

    @bungle – Thanks so much!

    # February 13, 2012 at 11:51 pm

    The broken part is when i click on the Schedule link from the schedule page. Its trying to load http://thishope.org/schedule/schedule.php rather than /schedule.php so maybe you need to make sure your menu links are prefixed with /

    I can’t find a way to navigate to Nov? how are you getting to there?

    # February 13, 2012 at 11:54 pm

    the SQL is storing the time in time format so that’s good news

    Can you try modifying line 534 of gigs-classes.php so that instead of

    $p->search("`gigID` = " . (int) $this->id, "`time`");

    it reads

    $p->search("`gigID` = " . (int) $this->id, "`time` ASC");

    and see if anything changes? If that doesn’t work try

    $p->search("`gigID` = " . (int) $this->id, "str_to_date(`time`,'%l:%i')");
    # February 14, 2012 at 12:12 am

    I may have messed up the quoting in that last one

    If that one breaks your php then try


    $p->search("`gigID` = " . (int) $this->id, "str_to_date(`time`,`%l:%i`)");
    # March 1, 2012 at 2:33 pm

    Thanks @bungle. I tried both. Neither seems to make any difference.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".