It is currently Sat Jul 26, 2014 11:06 am Advanced search

Problem php

Technical support, bug reports and more.

Problem php

Postby lluiski » Thu Mar 01, 2012 5:17 pm

Dear Users

Currently I have a database and I have to generate some statistics which I like to know is how to display an array with a simple while showing me perfectly

Currently I have the following code
while ($ row = mysql_fetch_array ($ query)) {
echo "<tr>";
$ t = $ row [name];
echo $ t;
}

The problem I put encuado introduce at:
xAxis: {
categories: [<? php echo join ($ t, ',')?>]
}

What I show are numbers and not the array of the result set that would have to be a series of words.

The question where you have to add the php within a xAxis
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Thu Mar 01, 2012 6:20 pm

I am not sure I completely understand what you are saying.

The variable '$t' that that you are setting in your while loop is not an array, so eching a join of $t will not do what you need.

You will need to build an array of values in your loop in order to output them to your categories array.
The HTML that you are outputting in that loop will also end up very ugly.

I would take this:
Code: Select all
while ($ row = mysql_fetch_array ($ query)) {
echo "<tr>";
$ t = $ row [name];
echo $ t;
}

and make it something like this:
Code: Select all
while ($row = mysql_fetch_array ($query)) {
    echo "<li>";
    $t = $row [name];
    echo $t;
    echo "</li>";

    $values[] = $t;
}

And then:
Code: Select all
xAxis: {
    categories: <? php echo json_encode($values); ?>
}
Last edited by jlbriggs on Thu Mar 01, 2012 10:09 pm, edited 3 times in total.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Thu Mar 01, 2012 6:52 pm

hello code

while ($ row = mysql_fetch_array ($ query)) {
echo "<li>";
$ T = $ row [name];
echo $ t;
echo "</ li>"

$ values ÔÇïÔÇï[] = $ t;
}


I put it out with <? php?> if so currently do not show me anything or have to add in the axis, I get the blank page if you add code
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Thu Mar 01, 2012 7:28 pm

I missed a semicolon after the last echo statement. code has been updated.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Thu Mar 01, 2012 7:42 pm

Now if I do not understand if the code that I have I add a new file only shows me nothing in fact, if I add yours does not work

If I add my code or yours inside to show the statistics do not show me anything on the page just shows me a blank page that can be, I'm adding the code wrong or not

What I want to put just a simple thing

http://jsfiddle.net/gh/get/jquery/edge/ ... umn-basic/


In the bottom exit the mysql query I want instead of the months that appear in the array, it is possible or not
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Thu Mar 01, 2012 9:12 pm

Yes, it's possible.
You have to pull your data from your database, build an array of the values in PHP, and then json_encode that array to provide a json array for the categories property of the x axis.

Since I don't know what else you are doing with your code, obviously my code may not be exactly what you need. You will need to edit it to suit your needs.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Thu Mar 01, 2012 9:19 pm

Whats the code use?
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Thu Mar 01, 2012 10:11 pm

At this point I will have to suggest that you look up introductory PHP/MySQL tutorials.
If the mysql query is returning the correct data, the code that I posted above should work.

If you post your complete code, and a link to the page in question, perhaps someone can be of more help.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Thu Mar 01, 2012 10:47 pm

My actual code:



<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>


<!-- 1. Add these JavaScript inclusions in the head of your page -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.twittenable.com/high/js/highcharts.js"></script>

<!-- 1a) Optional: add a theme file -->
<!--
<script type="text/javascript" src="http://www.twittenable.com/high/js/themes/gray.js"></script>
-->

<!-- 1b) Optional: the exporting module -->
<script type="text/javascript" src="http://www.twittenable.com/high/js/modules/exporting.js"></script>


<!-- 2. Add the JavaScript to initialize the chart on document ready -->
<script type="text/javascript">
<?php

$bd_host = "localhost";
$bd_usuario = "root";
$bd_password = "xxx";
$bd_base = "bbdd";
$con = mysql_connect($bd_host, $bd_usuario, $bd_password);
mysql_select_db($bd_base, $con);
$query=mysql_query("select consult ",$con);

while ($row = mysql_fetch_array ($query)) {
echo "<li>";
$t = $row [name];
echo $t;
echo "</li>";
$values[] = $t;
}

?>

var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
//categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
categories: <? php echo json_encode($values); ?>

},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
shadow: true
},
tooltip: {
formatter: function() {
return ''+
this.x +': '+ this.y +' mm';
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

}]
});
});

</script>

</head>
<body>

<!-- 3. Add the container -->
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>


</body>
</html>
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Thu Mar 01, 2012 10:52 pm

This is going to be an issue: "categories: <? php" it needs to be "categories: <?php" with no space between the ? and the php.

Beyond that, if you still don't get what you want you need to make sure that your mysql query is returning the data that you expect, and that the $values array is displaying what it should, and that the result of the json_encode($values) displays as it should.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Thu Mar 01, 2012 11:38 pm

the query I have it correctly, but does not display anything on the web as usual, is there anything I do wrong?

he error will not be in the beginning? there any example I can find to see if I have misplaced something
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Fri Mar 02, 2012 12:14 am

I pointed out one error in my previous post. That error will stop your PHP in that section from being executed, which will stop your categories array from being populated and probably throw a javascript error that will stop the chart from being drawn at all.

Are you outputting the results of your json_encode() function to see what is being sent to chart?
What is displaying on the page? Do you get a chart with no data? No chart at all? Nothing on the page at all?

If you can link to the page in question it will be a lot easier.

There is a MySQL example in the FAQ that may or may not help you:
viewtopic.php?f=10&t=8649
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Fri Mar 02, 2012 9:45 am

lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Re: Problem php

Postby jlbriggs » Fri Mar 02, 2012 3:21 pm

Ok, a couple of issues:

1) you are outputting your HTML inside your script tags:

Code: Select all
<script type="text/javascript">
<li>eraser</li><li>Kfe Innovacion</li><li>Miguel Urd´┐¢n</li><li>Marga</li><li>´┐¢ngel Prada</li><li>Luis Octavio Alpizar</li><li>Juan Bueno Jim´┐¢nez</li><li>Juanfra Alvarez</li><li>Juanjo Morales</li><li>ainhoa</li><li>Carlos Gonz´┐¢lez Ruiz</li>var chart;
$(document).ready(function() {
...

You need to move that outside the script tags, as it is causing a javascript error.

2) the names are being fed to the chart, but they are not in quotes, which will cause a problem.
Code: Select all
categories: [eraser,Kfe Innovacion,Miguel Urd´┐¢n,Marga,´┐¢ngel Prada,Luis Octavio Alpizar,Juan Bueno Jim´┐¢nez,Juanfra Alvarez,Juanjo Morales,ainhoa,Carlos Gonz´┐¢lez Ruiz]

Are you using json_encode() or join()? json_encode() should automatically include the needed quotes.
fiddles: http://jsfiddle.net/jlbriggs/J9JLr/
jlbriggs
 
Posts: 1458
Joined: Tue Sep 21, 2010 4:33 pm

Re: Problem php

Postby lluiski » Fri Mar 02, 2012 3:34 pm

the moment join



categories: [<?php echo join($values, ',') ?>],
lluiski
 
Posts: 16
Joined: Thu Mar 01, 2012 4:25 pm

Next

Return to Highcharts Usage

Who is online

Users browsing this forum: ayorhan, Google [Bot] and 6 guests