Script author: jon
Sorting data
     It is shown in this example how to sort random data with the help of php-scripts. Script creates a table with the generated random meanings of the time/date for the past 30 days and the sum on the page It imitates the expenses for the indicated period at the exact time. Any data of the two fields can be sorted by increase and decrease values on the page by pressing certain buttons. This script can be also used for sorting data, entered by the user. But it has to be slightly changed. It can be done by means of the form. The source code of this example is shown below.

In the template of the page:

<div align="center">
    <p>
        <b>This example shows the way of using the script to sort the data on expenses for the past 30 days</b>
    </p>
</div>
<hr>
<?$PHPCODE$("http://phpexample.ucoz.com/php/example002/example002.php")?>


PHP-script of this example:

<?
if ((count($_POST)>0) && $_POST['bdata'])
{
    $___notjson=1;
    $arr=split("\|",$_POST['bdata']);
    if ($_POST['sorttype']==11)
    {
        foreach ($arr as $line) {
            trim($line);
            list($value,$key) = split(",",$line,2);
            $sortarr[$key]=$value;
            $sorttoorigarr[$value]=$key;
        }
        sort($sortarr,SORT_NUMERIC);
        $data="<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><th>Date</th><th>Sum</th>";
        foreach ($sortarr as $val) {
            if ($val) $data.="<tr><td align=\"center\" width=\"50%\">".date("Y-m-d H:m:s",$val)."</td><td align=\"center\">".$sorttoorigarr[$val].".00 USD</td></tr>";
        }
        $data.="</table>";
        echo "$('#sorttable').html('$data')";
    }
    elseif ($_POST['sorttype']==12)
    {
        foreach ($arr as $line) {
            trim($line);
            list($value,$key) = split(",",$line,2);
            $sortarr[$key]=$value;
            $sorttoorigarr[$value]=$key;
        }
        rsort($sortarr,SORT_NUMERIC);
        $data="<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><th>Date</th><th>Sum</th>";
        foreach ($sortarr as $val) {
            if ($val) $data.="<tr><td align=\"center\" width=\"50%\">".date("Y-m-d H:m:s",$val)."</td><td align=\"center\">".$sorttoorigarr[$val].".00 USD</td></tr>";
        }
        $data.="</table>";
        echo "$('#sorttable').html('$data')";
    }
    elseif ($_POST['sorttype']==21)
    {
        foreach ($arr as $line) {
            trim($line);
            list($key,$value) = split(",",$line,2);
            $sortarr[$key]=$value;
            $sorttoorigarr[$value]=$key;
        }
        sort($sortarr,SORT_NUMERIC);
        $data="<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><th>Date</th><th>Sum</th>";
        foreach ($sortarr as $val) {
            if ($val) $data.="<tr><td align=\"center\" width=\"50%\">".date("Y-m-d H:m:s",$sorttoorigarr[$val])."</td><td align=\"center\">".$val.".00 USD</td></tr>";
        }
        $data.="</table>";
        echo "$('#sorttable').html('$data')";
    }
    elseif ($_POST['sorttype']==22)
    {
        foreach ($arr as $line) {
            trim($line);
            list($key,$value) = split(",",$line,2);
            $sortarr[$key]=$value;
            $sorttoorigarr[$value]=$key;
        }
        rsort($sortarr,SORT_NUMERIC);
        $data="<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><th>Date</th><th>Sum</th>";
        foreach ($sortarr as $val) {
            if ($val) $data.="<tr><td align=\"center\" width=\"50%\">".date("Y-m-d H:m:s",$sorttoorigarr[$val])."</td><td align=\"center\">".$val.".00 USD</td></tr>";
        }
        $data.="</table>";
        echo "$('#sorttable').html('$data')";
    }
    else echo "$('#sorttable').html('Data Error, reload the page')";
    exit;
}


$gtime=time();
srand($gtime);
$data="<div id='sorttable'><table border='1' cellpadding='0' cellspacing='0' width='100%'><th>Date</th><th>Sum</th>\n";
for ($i=0; $i<20; $i++)
{
 $tdate=rand($gtime-86400*30,$gtime);
 $summ=rand(1,5000);
 date("Y-m-d H:m:s",$tdate);
 $data.="<tr><td align='center' width='50%'>".date("Y-m-d H:m:s",$tdate)."</td><td align='center'>$summ.00 USD</td></tr>\n";
 $hdata.="$tdate,$summ|";
}
$data.="</table></div>
<form name='sortform' action='/php/example002/example002.php' method='post' onsubmit=\"_uPostForm(this,{dataType:'script'});return false;\" onerror=\"alert('Error');\">
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tr><td align='center' width='50%'>Sort by date [<input type='submit' value='A->Z' onclick='document.sortform.sorttype.value=11'>&nbsp;
<input type='submit' value='Z->A' onclick='document.sortform.sorttype.value=12'>]</td>
<td align='center'>Sort by sum [<input type='submit' value='A->Z' onclick='document.sortform.sorttype.value=21'>&nbsp;
<input type='submit' value='Z->A' onclick='document.sortform.sorttype.value=22'>]</td></tr></table>\n
<input type='hidden' name='bdata' value='$hdata'>
<input type='hidden' name='sorttype' value=0>
</form>";
echo $data;
?>
Date 18.02.2011
Download this example
Comments:
bljvdxut Spam 26.10.2014 23:09
Les deux petits meneurs ont sonné la révolte des Los Angeles Clippers.
On avait laissé Nene passablement énervé dans le game 3, après une altercation avec Jimmy Butler.
http://www.fuelpurification.com/docs/Nike-Blazer-70.asp - nike blazer femme

Entre Lance Stephenson et New York, il y a un lien particulier.
Lorsque je suis arriv茅 en NBA, je m’en suis remis 脿 Donyell Marshall et Robert Horry.
http://www.thetuscankitchen.com/PDF/j11-10-25.asp - jordan 11 space jam

La situation pourrait alors b茅n茅ficier 脿 Pablo Prigioni, victime d鈥檜n choc au nez contre les Suns mais dont la participation contre Charlotte n鈥檈st pas remise en cause.
J鈥檃i le sentiment d鈥檃voir trouv茅 mon shoot, il ne me reste plus qu鈥櫭?continuer de bosser dessus.
718028 google Spam 23.12.2013 09:55
http://www.google.com/
mbt sko tilbud carpinteyroszg Spam 09.12.2013 13:54
carpinteyrolin http://nike.dkbutik.org/online-nike-free-50-v4-2012-dame-løbesko-grøn-billige-salg-p-210.html

carpinteyroiqb http://nike.nobutikk.org/dame-nike-shox-nz-o-leven-iii-svart-rosa-sko-p-221.html

carpinteyrowle http://nike.dkbutik.org/nike-mænd-f2136-grå-hvid-sportstøj-suit-p-459.html

carpinteyrohnp http://nike.nobutikk.org/dame-nike-free-xt-motion-fit-blå-gul-jogge-sko-p-143.html

carpinteyroxue http://nike.dkbutik.org/nike-free-30-v2-kvinders-sko-2012-hot-hvid-grå-p-168.html

nikesbvy http://nike.dkbutik.org/grå-fluorescerende-grøn-nike-free-30-v2-mænd-sko-p-87.html
as Spam 13.07.2013 16:13
aaaaaaaaaa
Only registered users can add comments.
[ Registration | Login ]