Web Analytics Made Easy -
StatCounter Probably easy question on php Arrays - CodingForum

Announcement

Collapse
No announcement yet.

Probably easy question on php Arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Probably easy question on php Arrays

    I am hacking a graph producing php page to my own needs, but cant get my head around one aspect of it:-

    The code is taken from the graph app on this page:-
    http://www.puremango.co.uk/cm_php_graph_18.php

    PHP Graph is quite easy to use, but i want it to use dynamic data not the predefined title tags it has in source version.

    See my function so far that calls the graph.php:-

    Code:
    function Graphit() {
    	// start the session
    	session_start();
    	global $db, $prefix;
    	OpenTable();
    	$amountsarray=array();
    	$result = $db->sql_query( "select * from ".$prefix."_Salaries ORDER BY amount" );
    	while (list($salaryid,$certification,$currency,$country,$amount) = $db->sql_fetchrow($result)) {
    	             $salaryid = intval($salaryid);
    		$certification = stripslashes($certification);
    		$country = stripslashes($country);
    		$currency = stripslashes($currency);
    		$amount = intval($amount);
    		
    // Some code in here to populate the $_SESSION['amounts'] var with certification and amount
    
    	}
    
    	$_SESSION['currency'] = "USD";
    //	$_SESSION['amounts'] = Array("title1: "=>150,"title2: "=>200,"title3: "=>250); // This works fine but is predefined variables
    	// spit out the html for an img, calling this file, graph.php
    	echo '<center><img src="modules/SalarySurveyor/graph.php"></center>';
    }
    as you can see their is a line that does work which is as follows:-

    Code:
    $_SESSION['amounts'] = Array("title1: "=>150,"title2: "=>200,"title3: "=>250); // This works fine but is predefined variables
    but this just produces a graph with predefined value, i want mine to be pulled from database.

    I am fairly new to php and want to be able to populate the $_SESSION['amounts'] variable or Array ? with my two fields of $certification and $amount instead of "title1: "=>150

    I have played around but just cant get it to work.

    Is the $_SESSION['amount'] an array ?
    and what does the => signify ?

    i tried messing about with lines like:-
    array_push($amountsarray,$amount => $certification);

    and

    $_SESSION['amounts'] = Array("$certification: "=>$amount);

    but to no avail
    Any help muchly appreciated
    Last edited by MHFactsadmin; Jul 29, 2005, 08:12 PM.
Working...
X