0

i have been trying for a while to get dynamic sorting of my php results, but for somereason, it just doesn't do anything, if i try to change the sort fields in the dropdown, nothing happens and i can't figure it out.

Here is the php code

        $sortorder = "ASC";
$sortfield = "addon_name";

if(isset($_GET["sortorder"])) {
$sortorder = $_GET["sortorder"];
}
if(isset($_GET["sortfield"])) {
$sortfield= $_GET["sortfield"];
}

        $small_statement = "`addons` WHERE addon_size='small' ORDER BY $sortfield $sortorder";

AND here is the html code

   <select name="sortorder" onChange="MM_jumpMenu('parent',this,0)">
<option value="?sortorder=ASC">Ascending</option>
<option value="?sortorder=DSC">Descending</option>
</select>

<select name="sortfield" onChange="MM_jumpMenu('parent',this,0)">
<option value="?sortfield=addon_name">Name</option>
<option value="?sortfield=addon_rank">Rank</option>
</select></div><!---end browse_header--->
    <div id="small" class="tab_content">

    <?php 
          $browse_small_query = mysql_query("SELECT * FROM {$small_statement} LIMIT {$startpoint_small} , {$limit}");

          while($row_small = mysql_fetch_assoc($browse_small_query)) : ?>
            <?php extract($row_small);?>

                <div class="addon_wrapper" onclick="location.href='addon_detail.php?eid=<?php print "$estate_id";?> &aid=<?php print "$addon_id";?>';"><div class="addon_header"><?php print "$addon_name";?><?php print "$addon_id";?></div><!---end addon_wrapper---><div class="addon_browse_image"></div><!---end addon_browse_image---></div><!---end addon_wrapper--->
        <?php endwhile ?>

Thanks for any and all help

Al Hennessey
  • 2,395
  • 8
  • 39
  • 63

1 Answers1

0

Your <option>s have the wrong values. You don't need the name of the variable, because that's implied by <select name="XXX". The values should be

<option value="ASC">Ascending</option>
<option value="DESC">Descending</option>

Similar for the other two.

You could also have debugged this yourself by checking the values that make it inside $_GET.

Finally, this code is vulnerable to SQL injection because anyone can submit a request with whatever value they want for the two parameters. You should either employ a whitelist or use one of the standard defensive approaches to protect yourself.

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806