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
https://forums.phpfreaks.com/topic/186885-sorting-order-drop-down-menu/
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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.