Sorting Using PHP

I am a php novice so please be kind…. Need to sort date, after location has been selected.

    <div id="enroll_now">
  <form name="enroll" id="enroll" method="post" action="<?php echo get_permalink(762); ?>">
    <p>
      <label >Class Title</label>
      <input type="text" name="class_title" value="<?php echo $title;?>">
      </input>
    </p>
    <p>
      <label>Choose Location</label>
      <select name="location" id="location" >
        <option selected="selected" value="0">--Select Location--</option>
        <?php
        $result = mysql_query("SELECT * from wp_location WHERE class_id=$page_id ORDER BY location ASC");
        while($row = mysql_fetch_array($result))
        {
            echo "<option value=".$row['id'].">".$row['location']."</option>";

        }

    ?>
      </select>
    </p>
    <p>
      <label>Choose Date</label>
      <select name="choose_date" id="choose_date">
        <?php
        if (isset($datesavailable) && is_array($datesavailable)) {
        foreach($datesavailable as $val)
        {

        echo' <option value="'.$val.'">'.$val.'</option>n';
 }
 }
    ?>
      </select>
    </p>
    <p>
      <input type="image" src="<?php bloginfo('template_url'); ?>/images/confirm.png" alt="Confirm Information" />
    </p>
  </form>
</div>

The locations sorts fine, but then when I get to the date, I need them to sort by closest date first. Any help would be appricated. Thanks.

Related posts

Leave a Reply

3 comments

  1. I examined your page and see that you’re sending a POST (id & location) when the event change is triggered in your combo. My suggestion is to query the database like this

    SELECT * from wp_location WHERE class_id=$_POST['id'] AND location=$_POST['location'] ORDER BY date
    

    I’m assuming date field in your database is DATE, DATETIME or TIMESTAMP type.