Jump to content

Archived

This topic is now archived and is closed to further replies.

j3rmain3

Will not retrieve data from database

Recommended Posts

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.....

[code]<?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");

?>[/code]

Help !?!

Thanks

J3rmain3

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.