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

Go To StackoverFlow.com

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

2012-04-04 18:23
by Junaid Hussain


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%'
2012-04-04 18:26
by safarov
thank you for ntoicing that, and for highlighting the grammar too! however I am still getting the same error messag - Junaid Hussain 2012-04-04 18:32
try mysql_query($Requete,$db) or die(mysql_error()); to print the mysql erro - safarov 2012-04-04 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 3Junaid Hussain 2012-04-04 18:49
@JunaidHussain there is problem n your connection, check your host, user password and database - safarov 2012-04-04 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.ph - Junaid Hussain 2012-04-04 19:00
ok just to add that I have fixed the problem, only now I can't see to output the graph correctl - Junaid Hussain 2012-04-04 21:31
Ads