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 + 1 == $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
What's PHP? Well ermm
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 + 1 == $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 ();
?>
What's PHP? Well ermm
Dont worry ... worked it out
What's PHP? Well ermm
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
Forum Rules
Bookmarks