www.webdeveloper.com
Results 1 to 3 of 3

Thread: A array to create another array

  1. #1
    Join Date
    Jan 2006
    Location
    England UK
    Posts
    200

    Wink A array to create another array

    Hey

    Im having a small issue here... been wracking my brain all day, im using a 3rd party script that creates graphs, i am having problems trying to input an array data.

    The graph will display how many bookings went out for a castle.

    PHP Code:
    $database $db2;
    include 
    'cp_dbconnect.php';
    include 
    'functions/phpgraphlib.php';
        
    $castleQuery mysql_query("SELECT * FROM castles"); 
    while (
    $crow mysql_fetch_array($castleQuery)) {

        
    $castleName $crow['Castle_Name'];
        
    $bookQuery mysql_query("SELECT * FROM bookings WHERE Booking_Castle = '$crow[id]'");   
        
    $numBookings mysql_num_rows($bookQuery);     
        
        
    $results[] = '"'.$castleName.'"=>-'.$numBookings;

    }
        
        
    $cresults count($results);
        
        
    $d 'array(';
        while (list(
    $key,$valuea) = each($results)) {
        if (
    $key+== $cresults) {
        
    $last '';
        } else {
        
    $last ', ';
        }
        
        echo 
    "$valuea$last";
        
    // $t = "$valuea$last";

        
    }

        
    $a ');';
        
        
    $graph = new PHPGraphLib(500,350);
        
    $data "$d$t$a";
        
        echo 
    $data;

        
    $graph->addData($data);
        
    $graph->setTitle('Test');
        
    $graph->setGradient('red''maroon');
        
    $graph->createGraph(); 
    In the echo... it shows it correctly...

    "12x15 Ben 10"=>-1, "12x15 Peppa Pig"=>-2

    but when i try and make it a variable so i can use it else where it only shows the last one.

    "12x15 Peppa Pig"=>-2

    In the end this is what i am hoping.

    $data = array("12x15 Ben 10"=>-1, "12x15 Peppa Pig"=>-2);

    But i cannot manually input this, as it is getting the data from MySQL

    Please help its getting annoying!! Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    England UK
    Posts
    200
    I tried changing it around but its only showing 1 again

    PHP Code:

    <?php
    $database 
    $db2;
    include 
    'cp_dbconnect.php';
    include 
    'functions/phpgraphlib.php';
        
    $castleQuery mysql_query("SELECT * FROM castles"); 
    while (
    $crow mysql_fetch_array($castleQuery)) {

        
    $castleName $crow['Castle_Name'];
        
    $bookQuery mysql_query("SELECT * FROM bookings WHERE Booking_Castle = '$crow[id]'");   
        
    $numBookings mysql_num_rows($bookQuery);     
        
        
    $results[] = '"'.$castleName.'"=>-'.$numBookings;

    }
        
        
    $cresults count($results);
        
        while (list(
    $key,$valuea) = each($results)) {
        if (
    $key+== $cresults) {
        
    $last '';
        } else {
        
    $last ', ';
        }
        
        
    $rdata "$valuea$last";
        
    $data = array("$rdata");
            
        }
            
        
    print_r ($data);
        
        
    $graph = new PHPGraphLib(500,350);
        
    $graph->addData($data);
        
    $graph->setTitle('Test');
        
    $graph->setGradient('red''maroon');
        
    $graph->createGraph();

    ?>

  3. #3
    Join Date
    Jan 2006
    Location
    England UK
    Posts
    200
    Dont worry ... worked it out

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles