Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging entry running order for mysql
    primarykey
    data
    text
    <p>I'm not sure how to do this or even if it's possible. I have a table of entries, but I'd like to change the running order of the entries. I've got a field called 'ID' which is set to auto-increment. I want the people in the back end to change the order of the entries themselves. So for example, if they move one entry up then the one above will automatically move down.</p> <p>I've put up and down arrows by each entry, but am not sure what to do next. The code I've written is:</p> <pre><code>&lt;?php $id = $_GET['id']; $direction = $_GET['direction']; $menu = $_GET['menu']; con = mysql_connect("hostname", "user", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("table", $con); $sql = "SELECT priority FROM Menu WHERE ID = $_GET[id]"; list($curpos) = mysql_fetch_array(mysql_query($sql)); // Find new position if ($direction &gt; 0) { // To be moved up $sql = "SELECT priority FROM Menu WHERE priority &lt; $curpos AND ID = $id ORDER BY priority DESC LIMIT 1"; list($newpos) = @mysql_fetch_array(mysql_query($sql)); } else { // To be moved down $sql = "SELECT priority FROM Menu WHERE priority &gt; $curpos AND ID = $id ORDER BY priority ASC LIMIT 1"; list($newpos) = @mysql_fetch_array(mysql_query($sql)); } if ($newpos) { $sql = "UPDATE Menu SET priority = $curpos WHERE priority = $newpos AND Menu = $menu"; mysql_query($sql); $sql = "UPDATE Menu SET priority = $newpos WHERE ID = $id"; mysql_query($sql); } echo $msg; ?&gt; </code></pre> <p>but this doesn't seem to do anything, I've seen it working in things like cPanel's but really don't know how to implement it myself. I'd be grateful for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload