Search code examples
phpmysqlsyntaxpchart

creating charts with pchart and mysql - correct syntax from example provided


I am trying to generate a chart based on the example provided by pchart. Here is my code:

<?php
/* Include the pData class */

include("pchart/class/pData.class.php");

/* Create the pData object */

$myData = new pData();  

/* Connect to the MySQL database */

$db = mysql_connect("webhost", "user", "pass");

mysql_select_db("database",$db);


/* Build the query that will returns the data to graph */

$Requete = "SELECT * FROM `replies` WHERE `field` LIKE CONCAT ('%', Do you an interest in Green IT, '%')";

$Result  = mysql_query($Requete,$db);

$Yes=""; $No=""; $Undecided="";

while($row = mysql_fetch_array($Result));

{


/* Push the results of the query in an array */
$Yes[]   = $row["Yes"];
$No[] = $row["No"];
$Undecided[]    = $row["Undecided"];
}



/* Save the data in the pData array */

$myData->addPoints($Yes,"Yes");

$myData->addPoints($No,"No");

$myData->addPoints($Undecided,"Undecided");

?>

The error I'm getting is this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a4728588/public_html/charts.php on line 30

Which points to:

while($row = mysql_fetch_array($Result));

Any ideas on how to fix this so the chart is generated?

Thanks in advance


Solution

  • You have syntax error in your query. CONCAT() is for merging strings. Dont need in your query. Should be like this

    LIKE '%Do you an interest in Green IT%'