Results 1 to 2 of 2

Thread: let user sort Mysql result using PHP

  1. #1
    Join Date
    Feb 2013

    let user sort Mysql result using PHP


    Im trying to let the user sort the results after "Pris" and "sted" (Price and place).

    I tried following this guide . But i could not get it to work. Nothing happens at my page. Please let me know if you know what I do wrong, and il bold the code I made after the guide. Btw here is a link to the site I will leave my computer on for a couple of hours.

    <form name="myform">
    <select name="sort" id="sort" style="float: left;" onChange="javascript:document.myform.submit();">
        <option value="Sted">Sted</option>
        <option value="Pris">Pris</option>
    $con = mysql_connect("localhost","test","1","lokaler2");
    if (!$con)
      die('Could not connect: ' . mysql_error());
    mysql_select_db("steder2", $con);
    $result = mysql_query("SELECT * FROM lokaler2");
    $searchResultQuery = "
        SELECT id, Sted, Pris
        FROM lokaler2
        WHERE MATCH (name)
        AGAINST ('{$GLOBALS['input']}' IN BOOLEAN MODE)
        ORDER BY $sort";
    echo "<table id='tabbelresultat'>
    while($row = mysql_fetch_array($result))
      echo "<tr id='tabellresultat'>";
      echo "<td id='tabellresultat1'>" . $row['Sted']. '<p/>' .$row['Slag'] . '<p/>' . $row['Pris'] . "</td>";
        echo "<td id='tabellresultat'>" . $row['Tekst'] . "</td>";
    echo "<td id='tabellresultatbilde'>" . $row['Bilde']."</td>";
      echo "</tr>";
    echo "</table>";

  2. #2
    Join Date
    Nov 2012
    Assuming that everything works, except for the sort function. And register globals are off (Which they should be). Try
    ORDER BY $_REQUEST['sort']
    When a form is submitted, with register globals ON, the GET and POST variables are stored in their respective array global variables called $_GET[] and $_POST[]. You can also access it through $_REQUEST[] which holds both $_GET and $_POST.

    Good luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center