Order in a flat db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghiuryy
Forum Newbie
Posts: 1
Joined: Fri Jul 15, 2011 9:59 am

Order in a flat db

Post by ghiuryy »

i have a flat db click.txt like:

Code: Select all

2%%2011/07/05%%http://index.php%%99%%Adriana lima
3%%2011/07/05%%http://index.php%%174%%Ami Smart
4%%2011/07/05%%http://index.php%%66%%Audrina patrige
5%%2011/07/05%%http:///index.php%%111%%Beyonce 
6%%2011/07/05%%http://index.php%%150%%Avril lavigne
with below code show posts from click.txt like that : 2 ,3,4,5,6.

The question it`s if it possible to show posts form click.txt in this order, thanks 6,5,4,3,2

Code: Select all

<?php
require 'settings.php';
$lines = array();

$totalclicks = '';
$linewidth = '';
$maxclicks = 0;
$maxid = 0;
$noyet = 0;
$pp = 3;

$lines = file($settings['logfile2']);
$start = $_GET[start] ? $_GET[start] : 0 ;
   $sortby = $_COOKIE[sortby] ? $_COOKIE[sortby] : "time" ;
	if($_GET[sortby]){
		$sortby = $_GET[sortby];
		setcookie("sortby", $_GET[sortby], time()+86400 );
		header("location: add.php");
	}
if ($noyet == 0) {

	switch($sortby){
		case "time":
			$img_arr_final = $lines;
			break;
	}

	$total_images = count($img_arr_final);
	foreach ($lines as $thisline) {
        $thisline = trim($thisline);
list($id,$added,$url,$count,$linkname) = explode('%%',$thisline);
		$i++;
		if($i < $start+1) continue;
		if($i > $start + $pp) break;
		
		$link .= " 
		
		".$id." <a href=\"$u/link/click.php?id=".$id."\">".$linkname."</a> views ".$count."  <br>";
		
		
	}
	
	for($p=0; $p*$pp <  $total_images ; $p++){
		$active = ($p*$pp) == $start ? "active" : "" ;
		$page_htmo .= "<a href=\"$u/index.php?start=".($p*$pp)."\" class=\"$active pages\">".($p+1)."</a> ";
	}
	
	

	$arr_sortby = $lines;	
	
	foreach($arr_sortby as $k=>$v){

		if($sortby == $k){
			$sortby_html[] = "<strong>$v</strong>";
		} else {
			$sortby_html[] = "<a href=\"$url/index.php?sortby=$k\">$v</a>";
		}
		
	}	
	
	$sortby_htmo = implode(" | ", $sortby_html);
	

       echo <<<ghiuryy_com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<title></title>
		<meta name="description" content="" />
		<style type="text/css">
			#cw_image_gallery { width: $css_album_width; margin: auto; font: 12px verdana; text-decoration: none;  }
			#cw_image_gallery img { width: $css_thumb_width;  height: $css_thumb_height; border: 3px solid #033; }
			#sortby { text-align: right;  border-bottom: 1px solid #abc; padding: 10px; clear: both; }
			#pagenav { text-align: right; border-top: 1px solid #abc; padding: 10px; clear: both; }
			#pagenav a.pages { padding: 2px 5px; text-decoration: none; border: 1px solid #abc; background-color: #cde; }
			#pagenav a.pages:hover, #pagenav a.active { background-color: #036; color: #fff; }
			.img_thumb { float: left; text-align: center; font: 10px verdana; margin: 10px; }
			.img_thumb p, #cw_image_gallery.img_thumb a { margin: 0; padding: 0;}
			.mini { font: 9px verdana; }
		</style>
	</head>
	<body>

	<div id="cw_image_gallery">
		
		
		<div id="sortby"> </div>
		$link
		<div id="pagenav">Total Links: <strong>$total_images</strong> | $footer | Page: $page_htmo</div>
		
	</div>

	</body></html>
ghiuryy_com;
		
    }
	

?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Order in a flat db

Post by McInfo »

Post Reply