Jump to content


Photo

Will not retrieve data from database


  • Please log in to reply
2 replies to this topic

#1 j3rmain3

j3rmain3
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 02 October 2006 - 12:49 PM

I had a earlier post about how i am creating dynamic charts using Libchart, PHP & MySQL. But i have another problem

The coding will not retrieve the data from the database. I dont know what i am missing because i am used to displaying information using $player = $_POST['player']; but im not using a HTML form. I just want the data from the database to appear straight onto the graphs.

Here is the coding.....

<?php

include "libchart/libchart/libchart.php";

$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "goals";

$connection = mysql_connect($host,$user,$pass) or die ("Unable To Connect To Server"); #connect to server

mysql_select_db($db) or die ("Unable To Get Database"); #connect to database

$query = "SELECT * FROM goals_data";#set up the query

$result = mysql_query($query) or die ("ERROR in query: $query.".mysql_error());#run the query

$numplayers = mysql_num_rows($result);

#START CREATING THE CHART

$chart = new VerticalChart(500, 500);


for ($i=0; $i<=($numplayers-1);$i++) {
##echo "This is $l_name, and he has scored $goals goal(s)<p>";


$chart ->addPoint(new Point("$l_name","$goals"));

}

$chart ->setTitle("Goals Per Game");
$chart ->render("graphs/playerReport.png");

?>

Help !?!

Thanks

J3rmain3

#2 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 02 October 2006 - 01:28 PM

Hi

perhaps instead of

for ($i=0; $i<=($numplayers-1);$i++) {
##echo "This is $l_name, and he has scored $goals goal(s)<p>";
$chart ->addPoint(new Point("$l_name","$goals"));
}

try

while ($row = mysql_fetch_row($result))
{
  $l_name = $row[0]; // or whatever the index of name and goals is
  $goals = $row[1];  // also, perheps use "SELECT l_name,goals FROM goals_data" instead of *

##echo "This is $l_name, and he has scored $goals goal(s)<p>";
$chart ->addPoint(new Point("$l_name","$goals"));
}

I've never use the chart before so i cant help on that part... but the mysql may be useful...

good luck
Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)

#3 j3rmain3

j3rmain3
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 02 October 2006 - 01:48 PM

You're a flipping genius. It works.

thanks

J3rmain3




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users