Jump to content

Will not retrieve data from database


j3rmain3

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.