Jump to content

blacknight

Members
  • Posts

    271
  • Joined

  • Last visited

Posts posted by blacknight

  1. this si smaller and a lil simpler...

    note the 3 line xml -> php array converter...

     

    
    $xml = new SimpleXMLElement('teams.xml',NULL,true);
    $json = json_encode($xml);
    $array = json_decode($json,TRUE);
    
    echo '<pre>';
    echo 'Befor<br>';
    print_r($array);
    echo 'After<br>';
    sksort($array,'overallpoints');
    print_r($array); 
    
    function sksort(&$array, $subkey="id", $sort_ascending=false) 
    {
    
    	if (count($array))
            $temp_array[key($array)] = array_shift($array);
    
    	foreach($array as $key => $val){
    		$offset = 0;
    		$found = false;
    		foreach($temp_array as $tmp_key => $tmp_val)
    		{
    			if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey]))
    			{
    				$temp_array = array_merge(    (array)array_slice($temp_array,0,$offset),
                                                array($key => $val),
                                                array_slice($temp_array,$offset)
                                              );
    				$found = true;
    			}
    			$offset++;
    		}
    		if(!$found) $temp_array = array_merge($temp_array, array($key => $val));
    	}
    
    	if ($sort_ascending) $array = array_reverse($temp_array);
    
    	else $array = $temp_array;
    }
    

  2. move $rowyp = mysql_fetch_assoc($resultyp) out of the while statement and vardump $rowyp and see what it says and post it... other then that i dont see any thing that stands out...

  3. this is a function i use to sort my arrays
    
    [code
    function sksort(&$array, $subkey="id", $sort_ascending=false) 
    {
    
    	if (count($array))
            $temp_array[key($array)] = array_shift($array);
    
    	foreach($array as $key => $val){
    		$offset = 0;
    		$found = false;
    		foreach($temp_array as $tmp_key => $tmp_val)
    		{
    			if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey]))
    			{
    				$temp_array = array_merge(    (array)array_slice($temp_array,0,$offset),
                                                array($key => $val),
                                                array_slice($temp_array,$offset)
                                              );
    				$found = true;
    			}
    			$offset++;
    		}
    		if(!$found) $temp_array = array_merge($temp_array, array($key => $val));
    	}
    
    	if ($sort_ascending) $array = array_reverse($temp_array);
    
    	else $array = $temp_array;
    }
    

    sksort($yourarrayname,'overallpoints');

     

    and its done no need to make the assign the array to a new var it keeps the old one

  4. this is a simple fuction that will save the image to your server

    function save_image($inPath,$outPath)
    {
    //Download images from remote server
    $in=    fopen($inPath, "rb");
    $out=   fopen($outPath, "wb");
    while ($chunk = fread($in,8192))
    {
    	fwrite($out, $chunk, 8192);
    }
    fclose($in);
    fclose($out);
    if (file_exists($outPath))
    {
    	return true;
    }
    else
    {
    	return false;
    }
    }
    

  5. function shutdown()

    {

    $included_files = get_included_files();

     

    foreach ($included_files as $filename)

    {

        echo "$filename\n";

    }

    }

     

    register_shutdown_function('shutdown');

     

    and thats how its done the function will only run once the page pas finished all other functions its queued at the end of the process tree in php

  6. yea i made an error in muy code lol

    change

    $query ."WHERE WorkGroupID = '".$branch."' AND";

    to

    $query ."WorkGroupID = '".$branch."' AND";

     

    then change

    ON tblleaveapplication.employeeid = tblemployee.id";

    to

    ON tblleaveapplication.employeeid = tblemployee.id WHERE ";

     

    and as fopr the dropdown befor your while statement add

    <option value= "ALL" <? if ($branch=='ALL'){ echo 'selected'; } ?> >All Branches</option>

     

    and a side note dont use shorttags .. like <?  it can lead to to issues with servers allways use <?php

  7. i think i under stand try and fallow my example

     

    you ahve 5 people with grades

    john - 80

    bob  - 75

    mike - 88

    jan - 65

    tom - 25

    you want to run them throu the function to assign something like a gpa average based on a decimal system you are using?

    if so..

    you need to make the marks an array and pass them through the function using a for statement

     

    ex

    $results=array();
    foreach($marks as $student => $mark)
    {
          $results[$sutdent] = gpamark($mark);
    } 
    

    then printing $results should have your numbers..

     

    marks should appear like this

    $marks = array('john' => '80','bob' => '75','mike' => '88','jan' => '65','tom' => '25');

     

    hope that helps a lil...

  8. manualy add the select all branches to the dropdown list give it the value of all

    then this is where it gets a lil complicated

    this would be your new $query statement

     

    $query="SELECT *,
    MONTH(tblleaveapplication.DateFrom) as DFMonth,
    MONTH(tblleaveapplication.DateTo) as DTMonth,
    YEAR(tblleaveapplication.DateFrom) as DFYear
    FROM `tblleaveapplication`
    LEFT JOIN `tblemployee`
    ON tblleaveapplication.employeeid = tblemployee.id";
    if ($branch != 'ALL')
    {
    $query ."WHERE WorkGroupID = '".$branch."' AND";
    }
    $query ."(
    (MONTH(tblleaveapplication.DateFrom)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.")
    OR
    (MONTH(tblleaveapplication.DateTo)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.")
    )";
    

×
×
  • 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.