Jump to content

PravinS

Members
  • Posts

    459
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by PravinS

  1. Use this

     

     

    <?php
    function select_row($sql)
    {
    //echo $sql . "<br />";
    if ($sql!="")
    {
    	$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
    	if ($result)
    	{
    		while($row = mysql_fetch_assoc($result))
    			$data[] = $row;
    	}
    	return $data;
    }
    }
    
    function pagingSlot($sql, $recperpage, $pagesetlimit, $page, $class, $getvars)
    {
    $rescnt=mysql_query($sql);
    $totcnt=mysql_num_rows($rescnt);
       
    	if (!$page)   
    		$page = 1;
    	$first=(($page-1)* $recperpage);
    
    	$sql = $sql . " limit ".$first.",".$recperpage;
    	$res = select_row($sql);
       
    	$serial_no = ($page - 1) * $recperpage;
       
    	$t = ($totcnt/$recperpage);
    	$arr=split('[.]',$t);
    	if ($arr[1])
    		$totalpages=$arr[0]+1;
    	else
    		$totalpages=$arr[0];
       
    	if ($totalpages > $pagesetlimit)
    	{
    		if ($page > 1)
    			$pagesetstart = $page - 1;
    		else
    			$pagesetstart = $page;               
    		   
    		$pagesetend= ($pagesetstart-1) + $pagesetlimit;
    		if ($pagesetend > $totalpages)
    		{
    			$pagesetend = $totalpages;
    			$pagesetstart = $pagesetend - $pagesetlimit + 1;
    		}
    	}
    	else
    	{
    		$pagesetstart = 1;
    		$pagesetend = $totalpages;
    	}
       
    	$str = "";
    
    	if ($page > 1)
    	{
    		$prev = $page - 1;
    		$str.= "<a href='".$_SERVER['PHP_SELF']."?page=$prev".$getvars."'  class='".$class."'> << </a> | ";                                           
    	}
    	else
    	{
    		$str.= "<<  | ";   
    	}
    
    
    	for ($i=$pagesetstart; $i<=$pagesetend; $i++)
    	{       
       
    		if ($i <= $totalpages)
    		{
    			if (!$page)
    				$page=1;
    			if ($page==$i)
    				$str.= '<font color=red>'.$i.'</font> ';
    			else
    				$str.= "<a href='".$_SERVER['PHP_SELF']."?page=$i".$getvars."'  class='".$class."'>".$i."</a> ";
    		}                               
    	}
    
    	if ($page < $totalpages)
    	{
    		$next = $page + 1;
    		$str.= " | <a href='".$_SERVER['PHP_SELF']."?page=$next".$getvars."'  class='".$class."'> >> </a> ";                                           
    	}
    	else
    	{
    		$str.= " |  >>  ";
    	}
    
    if ($totcnt == 0)
    	$str = "";
       
    $arr["records"]=$res;
    $arr["link"]=$str;
    $arr["serial"]=$serial_no;
    return $arr;
    }        
    ?>
    

     

     

  2. Use this function, it list all files in current directory

     

     

    <?php
    if ($handle = opendir('.')) 
    {
    	echo "<ul>";
    	while (false !== ($file = readdir($handle))) 
    	{
    		if ($file != "." && $file != "..") {
    			echo "<li>$file</li>";
    		}
    	}
    	echo "</ul>";
    	closedir($handle);
    }
    ?>
    

     

  3. Try this function

    function sort_array($array, $key, $order)
    {
    if ($order=="DESC")
    	$or="arsort";
    else
    	$or="asort";
    for ($i = 0; $i < sizeof($array); $i++) 
    {
    	$sort_values[$i] = $array[$i][$key];
    } 
    $or($sort_values);
    reset ($sort_values);
    while (list ($arr_key, $arr_val) = each ($sort_values)) 
    {
    	$sorted_arr[] = $array[$arr_key];
    }
    return $sorted_arr;
    }
    
    

     

  4. Try this

    <?php
    function hex2rgb($hex){
    
    $rgb = array();
    $rgb['r'] = hexdec(substr($hex, 0, 2));
    $rgb['g'] = hexdec(substr($hex, 2, 2));
    $rgb['b'] = hexdec(substr($hex, 4, 2));
    return $rgb;
    
    }
    
    print_r(hex2rgb('ffffff'));
    
    $colors = hex2rgb('ffffff');
    
    echo "<br>".$colors['r'];
    
    ?>
    
    

     

  5. You can calculate total number of records in the table and then subtract 5 from it the your query will change as

     

     

     

    $displayrecords = $totalrecords - 5;
    $sql = "SELECT * from TABLENAME LIMIT 6, $displayrecords ";
    

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.