EN - Technical supportSort order


17.08.2012, 22:33 - wingsgb - webSPELL newbie - 14 Posts
Hi,

When adding videos to the site they are added from left to right/ top to bottom. So the newest ones end up at the bottom?

i searched and found the below code ordering them by date but it dosent seem to be the case, as i waited till the next day when the date had changed, added a video and it added it to the bottom of the list again.
safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date");
 
18.08.2012, 17:18 - wingsgb - webSPELL newbie - 14 Posts
anyone? be much appreciated
 
18.08.2012, 17:37 - Maidzen - webSPELL user - 303 Posts
Link to Video Addon pls

you can try to order descending
Code:
1.
safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date desc");

 
18.08.2012, 17:48 - wingsgb - webSPELL newbie - 14 Posts
Thanks for the response
Maidzen wrote:

Link to Video Addon pls

you can try to order descending
Code:
1.
safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date desc");


the link were they are displayed on page?

Everything arranges by oldest

I did try adding desc to the query but never worked.

Code:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
if(isset($_GET['action'])) $action = $_GET['action'];
else $action = '';

if(isset($_POST['save'])) {
     $title           =      $_POST['title'];
     $category      =      $_POST['category'];
     $uploader      =      $_POST['uploader'];
     $video           =      $_POST['video'];
     $type           =      $_POST['type'];
     $portal      =      $_POST['portal'];
     $embed           =      $_POST['embed'];
     if(isset($_FILES['vidpreview'])) $vidpreview = $_FILES['vidpreview'];
     else $vidpreview = null;
     $desc          =      $_POST['description'];
     $comments     =      $_POST['comments'];
     
     // Check what type is video: Portal or embed
     if(empty($video)) $videocode = $embed;
     else $videocode = $video;
     
     // Insert data then screenshot ---
     safe_query("INSERT INTO ".PREFIX."videos
          ( date, uploader, vidcatID, video, type, portal, title, description, comments )
            values
            ( '".time()."', '$uploader', '$category', '$videocode', '$type', '$portal', '$title', '$desc', '$comments' ) ");
          
     // Screenshot upload query ---     
     $filepath      =      "images/videos/";
     $id           =      mysql_insert_id();
     
     if($vidpreview['name'] != "") {
          move_uploaded_file($vidpreview['tmp_name'], $filepath.$vidpreview['name'].".tmp");
          @chmod($filepath.$vidpreview['name'].".tmp", 0755);
          $getimg = getimagesize($filepath.$vidpreview['name'].".tmp");

          $pic = '';
          if($getimg[2] == IMAGETYPE_GIF) $pic=$id.'.gif';
          elseif($getimg[2] == IMAGETYPE_JPEG) $pic=$id.'.jpg';
          elseif($getimg[2] == IMAGETYPE_PNG) $pic=$id.'.png';
          if($pic != "") {
               if(file_exists($filepath.$id.'.gif')) unlink($filepath.$id.'.gif');
               if(file_exists($filepath.$id.'.jpg')) unlink($filepath.$id.'.jpg');
               if(file_exists($filepath.$id.'.png')) unlink($filepath.$id.'.png');
               rename($filepath.$vidpreview['name'].".tmp", $filepath.$pic);
               safe_query("UPDATE ".PREFIX."videos SET vidpreview='".$pic."' WHERE vidID='".$id."'");
          }  else {
               @unlink($filepath.$vidpreview['name'].".tmp");
               $error = 'Image is in incorrect format!';
               die('<b>'.$error.'</b><br /><br /><a href="index.php?site=videos&amp;action=edit&amp;vidID='.$id.'">&laquo; Back</a>');
          }
     }
          
     header("Location: index.php?site=videos&action=watch&vidID=$id");
}

if(isset($_POST['saveedit'])) {
     $title           =      $_POST['title'];
     $category      =      $_POST['category'];
     $video           =      $_POST['video'];
     $type           =      $_POST['type'];
     $portal      =      $_POST['portal'];
     $embed           =      $_POST['embed'];
     if(isset($_FILES['vidpreview'])) $vidpreview = $_FILES['vidpreview'];
     else $vidpreview = null;
     $desc          =      $_POST['description'];
     $comments     =      $_POST['comments'];
     $vidID          =      $_POST['vidID'];
     
     if(empty($video)) $videocode = $embed;
     else $videocode = $video;
     
     safe_query("UPDATE ".PREFIX."videos SET date='$date',
                                   vidcatID='$category',
                                          video='$videocode',
                                          type='$type',
                                          portal='$portal',
                                          title='$title',
                                          description='$desc',
                                          comments='$comments'
                                          WHERE vidID='$vidID' ");
                                          
     // Screenshot upload query ---     
     $filepath      =      "images/videos/";
     $id           =      $vidID;
     
     if($vidpreview['name'] != "") {
          move_uploaded_file($vidpreview['tmp_name'], $filepath.$vidpreview['name'].".tmp");
          @chmod($filepath.$vidpreview['name'].".tmp", 0755);
          $getimg = getimagesize($filepath.$vidpreview['name'].".tmp");

          $pic = '';
          if($getimg[2] == IMAGETYPE_GIF) $pic=$id.'.gif';
          elseif($getimg[2] == IMAGETYPE_JPEG) $pic=$id.'.jpg';
          elseif($getimg[2] == IMAGETYPE_PNG) $pic=$id.'.png';
          if($pic != "") {
               if(file_exists($filepath.$id.'.gif')) unlink($filepath.$id.'.gif');
               if(file_exists($filepath.$id.'.jpg')) unlink($filepath.$id.'.jpg');
               if(file_exists($filepath.$id.'.png')) unlink($filepath.$id.'.png');
               rename($filepath.$vidpreview['name'].".tmp", $filepath.$pic);
               safe_query("UPDATE ".PREFIX."videos SET vidpreview='".$pic."' WHERE vidID='".$id."'");
          }  else {
               @unlink($filepath.$vidpreview['name'].".tmp");
               $error = 'Image is in incorrect format!';
               die('<b>'.$error.'</b><br /><br /><a href="index.php?site=videos&amp;action=edit&amp;vidID='.$id.'">&laquo; Back</a>');
          }
     }
     
     header("Location: index.php?site=videos&action=watch&vidID=$id");
     
}

if(isset($_GET['delete'])) {
     include("_mysql.php");
     include("_settings.php");
     include("_functions.php");

     if(!ispageadmin($userID)) die('You have no access!');

     $ds=mysql_fetch_array(safe_query("SELECT vidpreview FROM ".PREFIX."videos WHERE vidID='".$_GET['vidID']."'"));
     if($ds['vidpreview']) {
          $filepath = "images/videos/";
          if(file_exists($filepath.$screen)) @unlink($filepath.$screen);
     }

     safe_query("DELETE FROM ".PREFIX."videos WHERE vidID='".$_GET['vidID']."'");
     safe_query("DELETE FROM ".PREFIX."comments WHERE parentID='".$_GET['vidID']."' AND type='vi'");

     if(isset($close)) echo'<body onload="window.close()"></body>';
     else header("Location: index.php?site=videos");
}

/* --- ACTIONS --- */

if($action=="new") {

     $bg1=BG_1;
     $bg2=BG_2;
     $pagebg=PAGEBG;
     $border=BORDER;
     $bghead=BGHEAD;
     $bgcat=BGCAT;
     
     if(ispageadmin($userID)) {
     
          $allportals     = getvideoportals();
          $allcats      = getvideocats();     
          $comments = '<option value="0">Disable comments</option><option value="1">Enable user comments</option><option value="2">Enable comments</option>';
     
          eval ("\$videos_new = \"".gettemplate("videos_new")."\";");
          echo $videos_new;
     }

}

elseif($action=="edit") {

     $vidID = $_GET['vidID'];
     
     if(ispageadmin($userID)) {
          $ds = mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."videos WHERE vidID='$vidID'"));
          
          $title = getinput($ds['title']);
          
          if($ds['type']==1) {
               $video = getinput($ds['video']);
               $embed = '';
          }
          else {
               $embed = getinput($ds['video']);
               $video = '';
          }
          
          $desc = getinput($ds['description']);
     
          $bg1     = BG_1;
          $bg2     = BG_2;
          $pagebg     = PAGEBG;
          $border     = BORDER;
          $bghead     = BGHEAD;
          $bgcat     = BGCAT;
          
          //Dropdowns -> Choose active
          $allportals     = getvideoportals();
          $allportals = str_replace('value="'.$ds['portal'].'"', 'value="'.$ds['portal'].'" selected="selected"', $allportals);
          $allcats      = getvideocats();     
          $allcats      = str_replace('value="'.$ds['vidcatID'].'"', 'value="'.$ds['vidcatID'].'" selected="selected"', $allcats);
          $comments      = '<option value="0">Disable comments</option><option value="1">Enable user comments</option><option value="2">Enable comments</option>';
          $comments      = str_replace('value="'.$ds['comments'].'"', 'value="'.$ds['comments'].'" selected="selected"', $comments);
     
          if($ds['type']==1) {
               $type='<input onclick="document.getElementById(\'embed\').style.display = \'none\'; document.getElementById(\'portal\').style.display = \'block\'" type="radio" name="type" value="1" checked="checked" /> Portal &nbsp; <input onclick="document.getElementById(\'embed\').style.display = \'block\'; document.getElementById(\'portal\').style.display = \'none\'" type="radio" name="type" value="0" /> Embed';
               $display = 'none';
               $display2 = 'block';
          }
          else {
               $type='<input onclick="document.getElementById(\'embed\').style.display = \'none\'; document.getElementById(\'portal\').style.display = \'block\'" type="radio" name="type" value="1" /> Portal &nbsp; <input onclick="document.getElementById(\'embed\').style.display = \'block\'; document.getElementById(\'portal\').style.display = \'none\'" type="radio" name="type" value="0" checked="checked" /> Embed';
               $display = 'block';
               $display2 = 'none';
          }
     
          eval ("\$videos_edit = \"".gettemplate("videos_edit")."\";");
          echo $videos_edit;
     
     }

}

elseif($action=="watch") {
     $vidID = (int)$_GET['vidID'];
     $query = safe_query("SELECT * FROM ".PREFIX."videos WHERE vidID='".$vidID."'");
     
     eval ("\$title_videos = \"".gettemplate("title_videos")."\";");
     echo $title_videos;
     
     echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos\');return document.MM_returnValue" value="Home/ Latest" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=3\');return document.MM_returnValue" value="ISK Related" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=1\');return document.MM_returnValue" value="Planetside" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=2\');return document.MM_returnValue" value="Planetside 2" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=4\');return document.MM_returnValue" value="Planetside 2 Fan made" /> ';
     if(ispageadmin($userID)) echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&amp;action=new\');return document.MM_returnValue" value="New video" /><br /><br />';
     
     if(mysql_num_rows($query)) {
          $ds = mysql_fetch_array($query);
          
          safe_query("UPDATE ".PREFIX."videos SET views=views+1 WHERE vidID='".$vidID."'");
          
          $videoID = $ds['video'];
          $portal = $ds['portal'];
          $show = showvideo($videoID, $portal);
          $title = clearfromtags($ds['title']);
          $date = date("d.m.Y", $ds['date']);
          $type = $ds['type'];
          $uploader = getnickname($ds['uploader']);
          $views = $ds['views'];
          $description = cleartext($ds['description']);
          
          $comments_allowed = $ds['comments'];
          
          $bg1=BG_1;
          $bg2=BG_2;
          $pagebg=PAGEBG;
          $border=BORDER;
          
          if($type == 1) {
               $stream = showvideo($videoID, $portal);
          }
          else {
               $stream = htmloutput($videoID);
          }
          
          if(ispageadmin($userID)) $adminaction = '<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&amp;action=edit&amp;vidID='.$vidID.'\');return document.MM_returnValue" value="edit" />
          <input type="button" onclick="MM_confirm(\'Really delete this video?\', \'videos.php?delete=true&amp;vidID='.$vidID.'\');" value="Delete" />';
          else $adminaction = '';
        
          eval ("\$videos_watch = \"".gettemplate("videos_watch")."\";");
          echo $videos_watch;
          
          $parentID = $vidID;
          $type = "vi";
          $referer = "index.php?site=videos&amp;action=watch&amp;vidID=$vidID";

          include("comments.php");
     }
     else {
          echo 'Video can\'t be played!';
     }
}

elseif($action=="cat") {
     $vidcatID = (int)$_GET['vidcatID'];
     $query = safe_query("SELECT * FROM ".PREFIX."videos WHERE vidcatID='".$vidcatID."'" );
     
     eval ("\$title_videos = \"".gettemplate("title_videos")."\";");
     echo $title_videos;

     echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos\');return document.MM_returnValue" value="Home/ Latest" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=3\');return document.MM_returnValue" value="ISK Related" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=1\');return document.MM_returnValue" value="Planetside" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=2\');return document.MM_returnValue" value="Planetside 2" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=4\');return document.MM_returnValue" value="Planetside 2 Fan made" /> ';
     if(ispageadmin($userID)) echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&amp;action=new\');return document.MM_returnValue" value="New video" /><br /><br />';
     
     
     
     $n=1;
     if(mysql_num_rows($query)) {
          while($ds=mysql_fetch_array($query)) {
          
               if($n%2) {
                    $bg1=BG_1;
                    $bg2=BG_2;
               }
               else {
                    $bg1=BG_3;
                    $bg2=BG_4;
               }
               
               $title = clearfromtags($ds['title']);
               $vidID = $ds['vidID'];
               $videoID = $ds['video'];
               $vidpreview = $ds['vidpreview'];
               $portal = $ds['portal'];
               $date = date("d.m.Y", $ds['date']);
               $type = $ds['type'];
               $uploader = getnickname($ds['uploader']);
               $views = $ds['views'];
               $catname = getvidcatname($ds['vidcatID']);
               
               if($type==1) {
                    $preview = showvideothumb($videoID, $portal);
               }
               else {
                    // This code is for embed only
                    $preview = showvideothumb($vidpreview, $portal, 1);
               }
               
               
               eval ("\$videos = \"".gettemplate("videos")."\";");
               echo $videos;
               
               $n++;
          }
          echo '<div class="clearfloat"></div>';
     }
     else { echo 'Category deosn\'t exists!'; }
}

else {

     if(isset($_GET['page'])) $page=(int)$_GET['page'];
     else $page = 1;
     
     eval ("\$title_videos = \"".gettemplate("title_videos")."\";");
     echo $title_videos;
     
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=3\');return document.MM_returnValue" value="ISK Related" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=1\');return document.MM_returnValue" value="Planetside" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=2\');return document.MM_returnValue" value="Planetside 2" /> ';
        echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&action=cat&vidcatID=4\');return document.MM_returnValue" value="Planetside 2 Fan made" /> ';
     if(ispageadmin($userID)) echo'<input type="button" onclick="MM_goToURL(\'parent\',\'index.php?site=videos&amp;action=new\');return document.MM_returnValue" value="New video" /><br /><br />';
     
     $alle=safe_query("SELECT vidID FROM ".PREFIX."videos");
     $gesamt = mysql_num_rows($alle);
     $pages=0;

     $max='9';

     for ($n=$max; $n<=$gesamt; $n+=$max) {
          if($gesamt>$n) $pages++;
     }

     if($pages>1) $page_link = makepagelink("index.php?site=videos", $page, $pages);
       else $page_link='';

     if ($page == "1") {
          $ergebnis = safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date LIMIT 0,$max");
          $n=1;
     }
     else {
          $start=$page*$max-$max;
          $ergebnis = safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date LIMIT $start,$max");
          $n = ($gesamt+1)-$page*$max+$max;
     }
     
     //$allvideos = safe_query("SELECT * FROM ".PREFIX."videos ORDER BY date");
     $n=1;
     while($ds=mysql_fetch_array($ergebnis)) {
     
          if($n%2) {
               $bg1=BG_1;
               $bg2=BG_2;
          }
          else {
               $bg1=BG_3;
               $bg2=BG_4;
          }
          
          $title = clearfromtags($ds['title']);
          $vidID = $ds['vidID'];
          $videoID = $ds['video'];
          $vidpreview = $ds['vidpreview'];
          $portal = $ds['portal'];
          $date = date("d.m.Y", $ds['date']);
          $type = $ds['type'];
          $uploader = getnickname($ds['uploader']);
          $views = $ds['views'];
          $catname = getvidcatname($ds['vidcatID']);
          $vidcatID = $ds['vidcatID'];
          
          if($type==1) {
               $preview = showvideothumb($videoID, $portal);
          }
          else {
               // This code is for embed only
               if(!empty($vidpreview)) $preview = 'images/videos/'.$vidpreview;
               else $preview = 'images/videos/nopreview.jpg';
          }

          eval ("\$videos = \"".gettemplate("videos")."\";");
          echo $videos;
          
          $n++;
     }
     echo '<div class="clearfloat"></div>';
     if($pages>1) echo $page_link;
}
?>

 
18.08.2012, 18:04 - Maidzen - webSPELL user - 303 Posts
ok change each query with ORDER BY date to

Code:
1.
ORDER BY vidID desc




 
18.08.2012, 18:19 - wingsgb - webSPELL newbie - 14 Posts
Thank you for your help, all working as it should be now lächeln
 
18.08.2012, 23:06 - Maidzen - webSPELL user - 303 Posts
wingsgb wrote:

Thank you for your help, all working as it should be now lächeln


you're welcome