TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-10-2008, 07:37 PM   #1 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default Ordering using up/down arrows

Hi all,

I have a list of records (videos) that are ordered using a value in a field called 'theorder'. 1 is at the top of the list. When the user clicks up or down next to each of the videos then it takes its current position and either +1 or -1 from it, and whatever is in that position switches values with it.

Here is my code:
PHP Code:
// ---------------- CHANGE ORDER
if($_GET['order'] != "")
{
    
$ord_id $_SESSION['zUser'];
    
$ord_media $_GET['vid_id'];
    
$ord_order $_GET['order'];
    
    
    
// get current order position of video
    
$sql "SELECT * FROM yml_media WHERE id = '$ord_media' AND artist_id = '$ord_id' LIMIT 1";
    
$rs=mysql_query($sql,$conn) or errorEmail("003"mysql_error(), $current_page_url);
    while(
$row=mysql_fetch_array($rs))
    {        
        
$ord_video1_id $row["id"];
        
$ord_video1_order $row["theorder"];
        
$ord_video1_type $row["section"];
    }
    
    
    
// find which video already has the order requested
    
$sql "SELECT * FROM yml_media WHERE theorder = '$ord_order' AND artist_id = '$ord_id' AND section = '$ord_video1_type' LIMIT 1";
    
$rs=mysql_query($sql,$conn) or errorEmail("003"mysql_error(), $current_page_url);
    while(
$row=mysql_fetch_array($rs))
    {        
        
$ord_video2_id $row["id"];
        
$ord_video2_order $row["theorder"];
    }
    
    
    
// switch those two video locations
    
mysql_query("UPDATE yml_media SET theorder = '$ord_order' where id = '$ord_video1_id'") or die(mysql_error()); 
    
    
mysql_query("UPDATE yml_media SET theorder = '$ord_video1_order' where id = '$ord_video2_id'") or die(mysql_error()); 

    
    
    
}
// ---------------- CHANGE ORDER 
This is fine until something outside of this ordering is changed such as a video is deleted or moved to another section leaving a number missing in the sequence.

I'm sure there is a much better way of doing this - can anybody point me in the right direction?

Thanks
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design