1

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

safarov
  • 7,793
  • 2
  • 36
  • 52
Junaid Hussain
  • 45
  • 1
  • 10

1 Answers1

0

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%'
safarov
  • 7,793
  • 2
  • 36
  • 52
  • thank you for ntoicing that, and for highlighting the grammar too! however I am still getting the same error message – Junaid Hussain Apr 04 '12 at 18:32
  • try `mysql_query($Requete,$db) or die(mysql_error());` to print the mysql error – safarov Apr 04 '12 at 18:35
  • ok so i did as suggested, the mysql error is as follows: `Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/a4728588/public_html/charts.php on line 3` which points to `Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/a4728588/public_html/charts.php on line 3` – Junaid Hussain Apr 04 '12 at 18:49
  • @JunaidHussain there is problem n your connection, check your host, user password and database` – safarov Apr 04 '12 at 18:52
  • ok so I've checked the webhost and it seems to be working fine here is a link to the error: http://befoz.netau.net/charts.php and here is a link to the outputted data from mysql to create a table: http://befoz.netau.net/database.php – Junaid Hussain Apr 04 '12 at 19:00
  • ok just to add that I have fixed the problem, only now I can't see to output the graph correctly – Junaid Hussain Apr 04 '12 at 21:31