Help to disply data in image

images php coding issues or problems here.

Moderators: macek, egami, gesf

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Help to disply data in image

Postby menjada » Tue Feb 04, 2003 1:18 pm

My speciallity is not PHP. Therfore i ask u to help me.
I use the JPgraph to make a graph.

Bu i need convert? my sql/php question to this variabel:

$data1y=array(112,8,19,3,10,5);

Some sort of array i think.

My SQl/php question:

$sql = mysql_query("SELECT impressions FROM $table WHERE annons_id = '$annons_id' ORDER BY datum DESC");

And then???

Whole script:

$data1y=array(112,8,19,3,10,5);
$data2y=array(8,2,11,7,14,4);
$data3y=array(8,2,11,7,14,4);

// Create the graph. These two calls are always required
$graph = new Graph(600,200,"auto");
$graph->img->SetMargin(40,30,20,40);
$graph->SetScale("textlin");
$graph->SetShadow();

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b3plot = new BarPlot($data3y);
$b3plot->SetFillColor("red");

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));

// ...and add it to the graPH
$graph->Add($gbplot);

$graph->title->Set("Annonsstatistik");
$graph->xaxis->title->Set("Dag");
$graph->yaxis->title->Set("Stat");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

// Display the graph
$graph->Stroke();

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Wed Feb 05, 2003 3:58 am

assuming impressions returns "xx,xx,xx,xx,xx,xx";

$sql = mysql_query("SELECT impressions FROM $table WHERE annons_id = '$annons_id' ORDER BY datum DESC");
$data_count = 1;
while($out = mysql_fetch_array($sql))
{
eval("\$data" .$data_count. "y = array(" .$out['impressions']. ");");
$data_count++;
}

// Create the graph. These two calls are always required
etc etc

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Wed Feb 05, 2003 4:16 am

Ok i´m stupit. I get error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource, on line 7

JpGraph Error: Empty data array specified for plot. Must have at least one data point.

CODE:
$sql = mysql_query("SELECT impressions FROM $table WHERE annons_id = '00023' ORDER BY datum DESC");
$data_count = 1;
while($out = mysql_fetch_array($sql))
{
eval("\$data" .$data_count. "y = array(" .$out['impressions']. ");");
$data_count++;
}

// Create the graph. These two calls are always required
$graph = new Graph(700,300,"auto");
$graph->img->SetMargin(40,30,20,40);
$graph->SetScale("textlin");
$graph->SetShadow();

// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b3plot = new BarPlot($data3y);
$b3plot->SetFillColor("red");

// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));

// ...and add it to the graPH
$graph->Add($gbplot);

$graph->title->Set("Annonsstatistik");
$graph->xaxis->title->Set("Dag");
$graph->yaxis->title->Set("Stat");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

// Display the graph
$graph->Stroke();

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Wed Feb 05, 2003 4:36 am

hmmm, should work.

try removing the $sql from the while clause
while($out = mysql_fetch_array())

if that doesn't sort it, run an
echo mysql_error();
after the query and check the return is ok.

All you are being told there is that mysql_fetch_array() isn't returning the value of field 'impressions' .

Concentrate on getting the db info out before doing the image stuff - once that is done you can add the image stuff again
eg

$sql = mysql_query("SELECT impressions FROM $table WHERE annons_id = '00023' ORDER BY datum DESC");
$data_count = 1;
while($out = mysql_fetch_array())
{
echo 'data'.$data_count.'y = array('.$out['impressions'].');<br />';
echo mysql_error().'<br />';
$data_count++;
}

should result in
data1y = array(123,4,56,78,9,0);
data2y = etc

if it doesn't - the db querying is wrong

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Wed Feb 05, 2003 4:39 am

on a subnote:

try also adding datum and annons_id to the select clause as (some mysql builds) will not recognise WHERE or ORDER BY clauses if the fieldname isn't within the select

"SELECT annons_id, impressions, datum FROM

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Wed Feb 05, 2003 4:58 am

I´m AND IDIOT!

i didn´t defined the table, there fore the error in output.

Question?

when U say:

should result in
data1y = array(123,4,56,78,9,0);
data2y = etc

is data1y imressions, or is data1y and data2y the same variable but splittet in 2??

Because data2y is another datasource.

I add an updated sql question so we under stand eachother.

CODE:

$sql = mysql_query("SELECT impressions, clicks, clickthroug FROM $table WHERE annons_id = '00023' ORDER BY datum DESC");
$data_count = 1;
while($out = mysql_fetch_array())
{
echo 'data'.$data_count.'y = array('.$out['impressions'].');<br />';
echo mysql_error().'<br />';
$data_count++;
}

Want output:
data1y = array(123,4,56,78,9,0); //impressions
data2y = array(123,4,56,78,9,0); //clicks
data3y = array(123,4,56,78,9,0); //clicktrough

/Jörgen

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Wed Feb 05, 2003 5:19 am

OK here is the hole script and with URL preview:

This code:

$data1y=array(5,6,5,6,);//impressions
$data2y=array(5,6,5,6); //clicks
$data3y=array(5,6,5,6,);// clicktroughs

OUTPUTS: http://www.menjada.com/php_image/jpGraph/example221.php

This code:

$sql = mysql_query("SELECT impressions, spela, clicktrough FROM mon01 WHERE annons_id = '00023'");
$data_count = 1;
while($out = mysql_fetch_array($sql))
{
eval("\$data" .$data_count. "y = array(" .$out['impressions']. ");");
eval("\$data" .$data_count. "y = array(" .$out['spela']. ");");
eval("\$data" .$data_count. "y = array(" .$out['clicktrough']. ");");
$data_count++;
}

OUTPUTS:
http://www.menjada.com/php_image/jpGraph/example222.php

I want it like the first example. The first 3, is day1, the second 3 is day2 etc..

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Wed Feb 05, 2003 5:39 am

until you finally get round to telling us (well me in particular) what data is stored in which db_fields and the exact syntax of storing, every guess I make at your script will be just another guess.

so...

annons_id - 00023
impressions = 112,8,19,3,10,5 ? or just 112,8 ? or what?

without knowing which fields make up which array.... well - guesswork is guesswork.

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Wed Feb 05, 2003 5:51 am

i´m VERY sorry. But i don´t understand myself some times.

The database structure is a table whit these columns:

date, impressions, spela, clicktrough

The row is being updated by day

I want to output like example: http://www.menjada.com/php_image/jpGraph/example221.php

there 0 is a date and 1 is another date.

the output is like impressions = (5,7,etc...) where 5 is day 1 and 7 is day 2 etc..

This sholud be data1y

the same for the spela and clicktrough
where data2y = spela, and data3Y = clicktrough

I hope i explained my sekf correctly, and i hope u still want to help me?

PHP isn´t my speciallty, but i still need this to work.

Again sorry.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Wed Feb 05, 2003 10:49 am

ahhhhh

try

$sql = mysql_query("SELECT impressions, spela, clicktrough FROM mon01 WHERE annons_id = '00023'");
while($out = mysql_fetch_array($sql))
{
eval("\$data1y = array(" .$out['impressions']. ");");
eval("\$data2y = array(" .$out['spela']. ");");
eval("\$data3y = array(" .$out['clicktrough']. ");");
}

the previous example you tried (the one rationalizing data'.$data_count.'y = ..spela would just have been re-attributing value to data1y three times - the above should sort that.

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Wed Feb 05, 2003 11:29 am

I still don´t get it.

The script, works but it only displays like this:

http://www.menjada.com/php_image/jpGraph/example222.php

Are eval("\$data1y = array(" .$out['impressions']. ");"); making a total of the impressions?

I have at least 10 rows in the database whit differa
ent dates, it should be 10 bars (one bar is actally 3, data1, data2 and data3 are gouped), one for each day.

example http://www.menjada.com/php_image/jpGraph/example221.php
is suposed to show 4 days. Orange = Impressions Blue = spela and red = clicktrough, together 1 day of data.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Feb 06, 2003 3:21 am

ok - lets get a proper idea of your db

can you list a few rows of your db with field values and we can work out exactly what values from what fields need to be attributed to which indices of whatever arrays?

eg

Code: Select all

anons_id    | impressions    | spela    | clickthrough
----------------------------------------------------------------------------
00023    12,13,13      8,3,6   5,6,4
00024   13,45      5   12,12,12


also an indication of how the img manipulation runs the array data might be nice

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Thu Feb 06, 2003 3:34 am

The structure is.

annons_id | date | impressions | spela | clicktrough
-------------------------------------------------------------
0023 | 2003-03-03 | 55 | 12 | 3
0023 | 2003-03-04 | 60 | 10 | 5


Creates a new row depending on date. And updates the row depending on date. But the tabel can include different annons_id´s

Hope this explain.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Feb 06, 2003 6:02 am

ok - we need to while loop a return based on annons_id, sorted by date and update seperated indices of named arrays accordingly - easy stuff

$sql = mysql_query("SELECT impressions, spela, clicktrough, date FROM mon01 WHERE annons_id = '00023' ORDER BY date");
while($out = mysql_fetch_array($sql))
{
$data1y[] = $out['impressions'];
$data2y[] = $out['spela'];
$data3y[] = $out['clicktrough'];
}

and I'm not even going to say 'that should do the trick' this time.

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Thu Feb 06, 2003 6:11 am

I got this error??

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in example222.php on line 7

JpGraph Error: Empty data array specified for plot. Must have at least one data point.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Feb 06, 2003 9:49 am

check fieldnames date/annons_id/spela/clicktrough/impressions are all spelled case sensitively correct.

failing that, just
echo mysql_error();
on the line after $sql =

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Thu Feb 06, 2003 9:56 am

U are my HERO!!!!!!!!!!!!

Thanks so mutch!!

If i want to make a limit of 50?

/Jörgen

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Thu Feb 06, 2003 11:19 am

why? surely each month only has max 31 days.

anyhow - just put

LIMIT 50

at the end of the sql query.

quick limit notes: limit restricts the amount of records (rows) returned. a single numeric just limits the number, double numerics define a start and length - eg LIMIT 20,10 would return records #20 through #30.

menjada
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Feb 04, 2003 1:09 pm

Postby menjada » Sun Feb 09, 2003 11:42 am

Hi again. Thanks for the help last time. I know this is not the right thread to be. But i want to continue our disskution.

If i want to LIMIT the last 30 rows regarding the amount of rows in the table. The table kan include rows from different months. So i want only to disply the last 30 days.

/Jörgen


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest

cron