Jump to content

Sorting Order Drop Down Menu


Wayniac

Recommended Posts

Any suggestions on how I might be able to switch from newest entries to youngest trees? I can't get it to change between them when the drop down menu's item is switched.

 

Sorting Order</span><br>
                <select name="sort" class="textBox_center" id="sort" style="width:150px;">
                <option value="1">Newest Entries<?php $result = mysql_query("SELECT * FROM album ORDER BY dtime DESC",$connect); ?></option>
                <option value="2">Youngest Trees<?php $result = mysql_query("SELECT * FROM album ORDER BY age DESC",$connect); ?></option>
              </select>

Link to comment
Share on other sites

You could try something like:

Sorting Order</span><br>
                <select name="sort" class="textBox_center" id="sort" style="width:150px;">
                <option value="1" onclick="newestentries.display='block';youngesttrees.display='none'">Newest Entries</option>
                <option value="2" onclick="newestentries.display='none';youngesttrees.display='block'">Youngest Trees</option>
              </select>

 

And have two sections that would correspond to this:

<div id="newestentries" style="display: none">
<?php
      $result = mysql_query("SELECT * FROM album ORDER BY dtime DESC",$connect);
      while ($row = mysql_fetch_assoc($result))
      {
            echo(" <a href=\"image_script.php?albumid=" . $row["albumid"] . "\">" . $row["title"] . "</a><br />");
      }
?>
</div>
<div id="youngesttrees" style="display: none">
<?php
      $result = mysql_query("SELECT * FROM album ORDER BY age DESC",$connect);
      while ($row = mysql_fetch_assoc($result))
      {
            echo(" <a href=\"image_script.php?albumid=" . $row["albumid"] . "\">" . $row["title"] . "</a><br />");
      }
?>
</div>

 

Not sure if that's what you're looking for though.

Link to comment
Share on other sites

Thank you so much Stephen, this works better then amazing! Here is the working updated code with a few changes.

 

Sorting Order</span><br>
                <select name="sort" class="textBox_center" id="sort" style="width:150px;">
                <option value="1" onclick="newestentries.style.display='block';youngesttrees.style.display='none'">Newest Entries</option>
                <option value="2" onclick="newestentries.style.display='none';youngesttrees.style.display='block'">Youngest Trees</option>
              </select>

 

                              <div id="newestentries" style="display: block">
<?php
      $result = mysql_query("SELECT * FROM album ORDER BY dtime DESC",$connect);
      while ($row = mysql_fetch_assoc($result))
      {
            echo(" <a href=\"read_more.php?albumid=" . $row["albumid"] . "\">" . $row["title"] . "</a><br />");
      }
?>
</div>
<div id="youngesttrees" style="display: none">
<?php
      $result = mysql_query("SELECT * FROM album ORDER BY age DESC",$connect);
      while ($row = mysql_fetch_assoc($result))
      {
            echo(" <a href=\"read_more.php?albumid=" . $row["albumid"] . "\">" . $row["title"] . "</a><br />");
      }
?>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.