Results 1 to 3 of 3

Thread: Reorder..PHP/MYSQL

  1. #1

    Reorder..PHP/MYSQL

    Firstly: A thankyou to all of you whove been answerign my post on other topics...ive been so busy, i WILL get round to answerign you!

    http://www.zaidcrowe.co.uk/fyp/sitea.../gettracks.php

    Im tryign to get this script to allow a user to set the playlist from a dB. Each track has a track number in the database. By pressing up they mvoe the track up in the play list and down down. Effectivly all this means is 'swapping' track numbers with either the track above or below:

    PHP Code:
    <?
    if (isset($_POST['up'])){
    $tracknum $_POST['tracknum'];
    $base $tracknum;
    $prevTracknum $base -=1;

    include (
    "dbconnect.php");
    $selectprev "UPDATE tracks SET tracknum='$tracknum' WHERE tracknum='$prevTracknum'";
    $runprev mysql_query($selectprev);
    $conn->close;


    include (
    "dbconnect.php");
    $selectcur "UPDATE tracks SET tracknum='$prevTracknum' WHERE tracknum='$tracknum'";
    $run mysql_query($selectcur);
    $conn->close;

     


    }
    ?>
    Ive tried all sorts of incarnations of the script so this could be well out im aware (the connect include has been altered and doesnt show the actual path to my db connect script).

    Im sure this is such a simpel problem i just cannot get it working! All help muchly appreciated!

  2. #2
    looks like it works, am i missing something?

  3. #3

    Not missign anything...

    No im really not sure whats going wrong witht that version of the script...most often only one half executes leavign me with two tracks having extaly the same track number.

    Just in case anyones intereste this is what I ended up using:

    PHP Code:
    <?
    //PLAY LIST REARANGER
    //FOR MOVING TRACKS UP
    $id $_POST['id'];
    $tracknum $_POST['tracknum'];
    //gets total tracks
    include ("dbconnect.php");
    $selectTotal "SELECT * FROM tracks";
    $getTotal    mysql_query($selectTotal);
    $max mysql_num_rows($getTotal);
    if (isset(
    $_POST['up'])){
    $tracknum--;
    //if the new track number is less then  1...
    if ($tracknum 1){
    echo 
    "That tracks is already at the top of the playlist!";
    include (
    "upload.php");
    exit;
    }
    //if the new track number is greater then  max number...
    if ($tracknum $max){
    echo 
    "That tracks is already at the bottom of the playlist!";
    include (
    "upload.php");
    exit;
    }
    //move the edited track one up
    $selectcur "UPDATE tracks SET tracknum='$tracknum' WHERE id='$id'";
    $run mysql_query($selectcur);
    //moves the track above the edit track one down in its place!
    $tracknum++;
    $selectprev "UPDATE tracks SET tracknum='$tracknum' WHERE id!='$id' ";
    $tracknum--;
    $selectprev .= "AND tracknum = '$tracknum'";
    $runprev mysql_query($selectprev);
    $con->close;
    include (
    "upload.php");
    }
    //FOR MOVING TRACKS DOWN
    if (isset($_POST['down'])){
    $tracknum++;
    //if the new track number is less then  1...
    if ($tracknum 1){
    echo 
    "That tracks is already at the top of the playlist!";
    include (
    "upload.php");
    exit;
    }
    //if the new track number is greater then  max number...
    if ($tracknum $max){
    echo 
    "That tracks is already at the bottom of the playlist!";
    include (
    "upload.php");
    exit;
    }
    //move the edited track one up
    $selectcur "UPDATE tracks SET tracknum='$tracknum' WHERE id='$id'";
    $run mysql_query($selectcur);
    //moves the track above the edit track one down in its place!
    $tracknum--;
    $selectprev "UPDATE tracks SET tracknum='$tracknum' WHERE id!='$id' ";
    $tracknum++;
    $selectprev .= "AND tracknum = '$tracknum'";
    $runprev mysql_query($selectprev);
    $con->close;
    include (
    "upload.php");
    }
    ?>
    Im very new to PHP so if anyone can suggest ways in which to streamline the above or optimize it then lease drop me a line id appreaciate it!

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012