Niketheguy

try this code
it builds the string and echos it once thus we eliminate the chance that
echo might place line breaks in your <img > tag

*<html>
<head>
<title>
Nike's Second Attempt on Charts API with php
</title>
</head>
<body>

<?php

  include("db.php");
  $sql="SELECT * from test";
  $result = mysql_query($sql);
  // We will use a string variable $str to generate the <img tag>

  $str = "";
  $str =  "<img src=\'http://chart.apis.google.com/chart?chs=240x100";;
  $str = $str."&amp;chd=t:";
  $rows = mysql_num_rows($result);

  $i=1;
  while($row = mysql_fetch_array($result))
  {
    if($i < $rows)
    {
      $str = $str.$row['value'].",";
      $i=$i+1;
    }
    else
    {
      $str = $str.$row['value'];
      $i=$i+1;
    }
  }
  $str = $str."&amp;cht=lc";
  // We will close the src attribute with \' and to print escape character '
we shall precede it with \

  $str = $str."&amp;chxt=x,y\'";
  $str = $str." alt=\'Sample chart\' />";

  //we shall echo the $str that will display the graph
  echo $str;

?>
</body>
</html>

Asad
*






On Tue, Mar 3, 2009 at 11:42 PM, niketheguy <[email protected]> wrote:

>
> I am currently trying to incorporate charts api into my project by
> interfacing it with my MYSQL DB.I am using PHP..this is the code i
> have written..It seems right to me but the chart does not get
> displayed..would appreciate help in this matter
> Thanks in advance.
>
> Here is the code...
> <html>
> <?php
>
> include("db.php");
> $sql="SELECT * from test";
> $result = mysql_query($sql);
> echo "<img src='http://chart.apis.google.com/chart?chs=240x100 ";
> echo "&amp;chd=t:";
> $rows = mysql_num_rows($result);
>
> $i=1;
> while($row = mysql_fetch_array($result))
> {
>
> if($i < $rows){
> echo $row['value'].",";
> $i=$i+1;}
>
> else
> {
> echo $row['value'];
> $i=$i+1;
> }
>
>
> }
> echo " &amp;cht=lc";
> echo " &amp;chxt=x,y";
> echo " alt='Sample chart'/></img>";
>
>
> ?>
> </html>
>
>
> The table contains values of type INT whc im trying to display through
> the chart.I double checked the generated source of this page and it is
> perfectly alright with no anomalies observable to me..I hope someone
> could help me..Thanks.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Chart API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-chart-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to