Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

array fault using with mysql and php

Codes here !

Moderators: macek, egami, gesf

array fault using with mysql and php

Postby elkara » Wed Aug 01, 2012 6:42 am

Code: Select all

<?php

include('phpgraphlib.php');
$graph = new PHPGraphLib(500,350);
$sonuc=array(0,0,0,1000,0,0,2000,0,0,0,0,0);



$graph->addData($sonuc);
$graph->setTitle('Widgets Produced');
$graph->setGradient('yellow', 'green');
$graph->createGraph();
?>
 


My code is working like that, but l wanna get the values from mysql, thats why l changed thecreating array part with below code

Code: Select all

$date=date("Y-m-d");
$kk= date("m",strtotime($date));
$ss=date("Y",strtotime($date));
echo $date;
echo $ss."</br>";

$k=0;




while($k<12){
   $i=0;

   $results=mysql_query("SELECT * FROM new where month(date)='$kk' and year(date)='$ss' and erisim='1'");
   while($sayi=mysql_fetch_array($results,MYSQL_ASSOC)){
      $i++;   
      }
      
      $sonuc[$k]=$i;
      echo $sonuc[$k]."</br>";
      $date = strtotime ( '+1 month' , strtotime ( $date ) ) ;
$date = date ( 'y-m-d' , $date );
   
   $k++;
   
   
$kk= date("m",strtotime($date));
$ss=date("Y",strtotime($date));

}



but it's not working like this. They are creating the same array but when l do it using mysql, lt's not working. Please help me. If you want l can post phpgraphlib.php code too.
elkara
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 01, 2012 6:30 am

Re: array fault using with mysql and php

Postby johnj » Wed Aug 01, 2012 8:42 pm

you are fetching the data from mysql into the variable $sayi. After that, where are you using this???
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: array fault using with mysql and php

Postby elkara » Wed Aug 01, 2012 11:13 pm

johnj wrote:you are fetching the data from mysql into the variable $sayi. After that, where are you using this???


l just try to count saved dates number using fetching. l want to draw a graph which will show saved datas number at mysql database per month.
elkara
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 01, 2012 6:30 am

Re: array fault using with mysql and php

Postby NigelRen » Wed Aug 01, 2012 11:37 pm

I'm not sure what your trying to achieve here with your SQL.
With your $k loop I assume your trying to go through each month - but with your SQL your checking 'month(date)='$kk'' - so your using the month from $kk instead?
As an aside - you could make the SQL do more of the work for you by doing something like
Code: Select all
select count(*)
   from new
   where erisim = '1' and year(date)='$ss
   group by month(date)
   order by month(date)

You could extend the idea to group by year as well which would give you a set of results which can be graphed easily.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: array fault using with mysql and php

Postby elkara » Wed Aug 01, 2012 11:48 pm

NigelRen wrote:I'm not sure what your trying to achieve here with your SQL.
With your $k loop I assume your trying to go through each month - but with your SQL your checking 'month(date)='$kk'' - so your using the month from $kk instead?
As an aside - you could make the SQL do more of the work for you by doing something like
Code: Select all
select count(*)
   from new
   where erisim = '1' and year(date)='$ss
   group by month(date)
   order by month(date)

You could extend the idea to group by year as well which would give you a set of results which can be graphed easily.

It is usefull than my code.l am new at php and it seems there is still lots of thing l have to learn :) .Thanx. But still l cant draw a graph using values from mysql database.
elkara
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 01, 2012 6:30 am

Re: array fault using with mysql and php

Postby NigelRen » Wed Aug 01, 2012 11:52 pm

Have you tried replacing the $kk with $k in your original code?
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: array fault using with mysql and php

Postby elkara » Thu Aug 02, 2012 12:04 am

NigelRen wrote:Have you tried replacing the $kk with $k in your original code?

Both of two codes are working seperately. l can create array correctly. My problem is when l replace
$sonuc=array(....) at first code with below code,my graph code won't work.
elkara
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 01, 2012 6:30 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.