0

Hi all,

I have a query pulling out dates from a database, these dates are then added to an array and inserted into a graph along the x-axis. From the results, there could be one value with one date or there could be 10 values with one date. This means that the data displayed on the x-axis is inconsistent. What I need to do is to add the unique dates ONLY to the array, which will allow the graph to have more clarity.

<?php
$get_testruns = mysql_query("SELECT testrun_id,logs,req_iter,comp_iter,tools FROM (testrun tr) left join log_servers ls on tr.log_servers_id = ls.log_servers_id WHERE test_codelevel_id='695259' ORDER BY end") or die(mysql_error());
	
	$x = 0;
	$y = 0;
	while ($result = mysql_fetch_assoc($get_testruns)) {
	
		$testrun_id = $result['testrun_id'];
		$getdate = mysql_query("select end from testrun where testrun_id = '$testrun_id'") or die(mysql_error());

		while ($date = mysql_fetch_assoc($getdate)) {
			$end = $date['end'];
                    // Need something here to process unique dates
			$formatted_date = date("d/m/Y",$end);
    		}

		$req_iter = $result['req_iter'];
		$comp_iter = $result['comp_iter'];
		
		$arrData[$x][1] = $formatted_date;    //x-axis
		$arrData[$y][2] = $comp_iter;    //y-axis
		  
		$x++;
		$y++;
	}
?>

Many thanks ;), Nonshatter x

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by paulrajj
0

Hi,

In PHP, array_unique will do this for u. check the below function,

function arrayUnique($array, $preserveKeys = false)
{
    // Unique Array for return
    $arrayRewrite = array();
    // Array with the md5 hashes
    $arrayHashes = array();
    foreach($array as $key => $item) {
        // Serialize the current element and create a md5 hash
        $hash = md5(serialize($item));
        // If the md5 didn't come up yet, add the element to
        // to arrayRewrite, otherwise drop it
        if (!isset($arrayHashes[$hash])) {
            // Save the current element hash
            $arrayHashes[$hash] = $hash;
            // Add element to the unique Array
            if ($preserveKeys) {
                $arrayRewrite[$key] = $item;
            } else {
                $arrayRewrite[] = $item;
            }
        }
    }
    return $arrayRewrite;
}
$arrData = arrayUnique($arrData);

Edited by paulrajj: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.