treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] php gig list not ordering AM-PM correctly

  • 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.
  • 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.
  • @lyleyboy - How do I look in the database and where do I look?
  • 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?
  • 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?
  • @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?
  • 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.
  • Worse yet it may not be storing time in a sortable format rather as a string. I'll take a look.
  • @bungle - Thanks so much!
  • 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?
  • 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')");
  • 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`)");
  • Thanks @bungle. I tried both. Neither seems to make any difference.