I set up a HighChart to look at a MySQL database via a JSON feed, however the problem I have is that if the stacked column chart displays January to December from left to right the Legend shows it in reverse order December to January left to right.
Having tried to re-order the series in the code and poking around on the HighCharts information I am at a dead end.
Is this correctable, and if so could you let me know what to change please? Thanks.
Here's my code:
<?php
$con = mysql_connect("***","***","***");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("***", $con);
$query = mysql_query("SELECT * FROM viewByMonth");
$category = array();
$category['name'] = 'variety';
$series1 = array();
$series1['name'] = 'Jan';
$series2 = array();
$series2['name'] = 'Feb';
$series3 = array();
$series3['name'] = 'Mar';
$series4 = array();
$series4['name'] = 'Apr';
$series5 = array();
$series5['name'] = 'May';
$series6 = array();
$series6['name'] = 'Jun';
$series7 = array();
$series7['name'] = 'Jul';
$series8 = array();
$series8['name'] = 'Aug';
$series9 = array();
$series9['name'] = 'Sep';
$series10 = array();
$series10['name'] = 'Oct';
$series11 = array();
$series11['name'] = 'Nov';
$series12 = array();
$series12['name'] = 'Dec';
while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['variety'];
$series1['data'][] = $r['Jan'];
$series2['data'][] = $r['Feb'];
$series3['data'][] = $r['Mar'];
$series4['data'][] = $r['Apr'];
$series5['data'][] = $r['May'];
$series6['data'][] = $r['Jun'];
$series7['data'][] = $r['Jul'];
$series8['data'][] = $r['Aug'];
$series9['data'][] = $r['Sep'];
$series10['data'][] = $r['Oct'];
$series11['data'][] = $r['Nov'];
$series12['data'][] = $r['Dec'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);
array_push($result,$series4);
array_push($result,$series5);
array_push($result,$series6);
array_push($result,$series7);
array_push($result,$series8);
array_push($result,$series9);
array_push($result,$series10);
array_push($result,$series11);
array_push($result,$series12);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
You can reverse legend order by parameter: reversed
Related
$caballoganador = rand(1,9);
$selectganadores3 = array();
$arrayresultados = array();
$selectGanadores ="SELECT `usuario` from `jugadacaballo` WHERE `caballo` =' $caballoganador'";
$selectGanadores1 = mysqli_query($conn, $selectGanadores);
while($selectganadores2 = mysqli_fetch_assoc($selectGanadores1)){
$selectganadores3 = $selectganadores2['usuario'];
array_push($arrayresultados,$selectganadores3);
}
Why the results are not pushing into the array? I'm new with Programming, sorry for my errors.
Try it with $arrayresultados[]
$caballoganador = rand(1,9);
$selectganadores3 = array();
$arrayresultados = array();
$selectGanadores ="SELECT `usuario` from `jugadacaballo` WHERE `caballo` ='$caballoganador'";
$selectGanadores1 = mysqli_query($conn, $selectGanadores);
while($selectganadores2 = mysqli_fetch_assoc($selectGanadores1)){
$arrayresultados[] = $selectganadores2['usuario'];
}
<?php
include 'dbh.php';
session_start();
if (isset($_GET['gmail'])) {
$gname = $_GET['gmail'];
}
$gname = mysqli_real_escape_string($connect, $gname);
$_SESSION['myusername'] = $gname;
$today = date("d.m.y");
$k=0;
$sql = "SELECT cart_fext FROM cart WHERE cart_sess = '$sess'";
$result=mysqli_query($connect, $sql);
$kode[$k] = array();
$kame[$k] = array();
$kesc[$k] = array();
$kail[$k] = array();
$kid[$k] = array();
$kate[$k] = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
extract($row);
$k = $k + 1;
$cname=$row['cart_item_name'];
$csize=$row['item_size'];
$cdesc=$row['cart_desc'];
$cfpath=$row['cart_fpath'];
$cfext=$row['cart_fext'];
$ccode=$row['cart_itemcode'];
$cuserid=$row['cart_usrid'];
$kode[$k] = $ccode;
$kame[$k] = $cname;
$kesc[$k] = $cdesc;
$kail[$k] = $gname;
$kid[$k] = $cuserid;
$kate[$k] = $today;
}
for($i=1; $i<=$k; $i++) {
$sqlsal = "INSERT INTO sales (s_code, s_name, s_desc, s_mail, s_userid, s_date) VALUES ('$kode[$i]', '$kame[$i]', '$kesc[$i]', '$kail[$i]', '$kid[$i]' ,'$kate[$i]')";
$result=mysqli_query($connect, $sqlsal);
}
header("location:makedir.php");
?>
my table sales is just not accepting data, dbh.php is to connect to the database
I don't understand what is wrong with this script?
please help?
I have checked your insert query it is running fine but I think the problem is with your SELECT query
SELECT cart_fext FROM cart WHERE cart_sess = '$sess'
please print the result of the query. I think that it may not be giving any result.
How to connect 2 arrays? I want that $new[$code]=$color, how can I do this? Below is my code:
$sql = "SELECT user_id, user_color FROM dotp_users";
$result = mysql_query($sql) or die(mysql_error());
$code = $color = array();
while($row = mysql_fetch_assoc($result)) {
$code[] = $row['user_id'];
$color[] = $row['user_color'];
}
Declare the variable outside the while loop
$new = array();
Then inside while loop
$new[$row['user_id']] = $row['user_color'];
In the while loop...
$sql = "SELECT user_id, user_color FROM dotp_users";
$result = mysql_query($sql) or die(mysql_error());
$code = $color = array();
while($row = mysql_fetch_assoc($result)) {
$new[$row['user_id']] = $row['user_color'];
}
If you need the arrays seperate for some reason you can do it later using array_combine, http://php.net/manual/en/function.array-combine.php.
$sql = "SELECT user_id, user_color FROM dotp_users";
$result = mysql_query($sql) or die(mysql_error());
$code = $color = array();
while($row = mysql_fetch_assoc($result)) {
$code[] = $row['user_id'];
$color[] = $row['user_color'];
}
...
$new = array_combine($code, $color);
coupon = 700,701,702,703
startdate = 25-02-2015
For example - Now there are 4 values present inside coupon column.
what I Need
When I search 700 , then it selects startdate and add +1 months to startdate because 700 is in 1st position and it generates output like below
for ex- 25-03-2015
When I search 701 then it get startdate and +2 months in startdate because 701 is in 2nd position and it generates output like below
for ex- 25-04-2015
<?php
if(!empty($_GET['q'])) {
$db = new PDO('mysql:host=localhost;dbname=circulation_scheme_prepaid', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q = $_GET['q'];
$result = $db->prepare('SELECT * FROM receipt_entry WHERE coupon = :coupon');
$result->execute(array(':coupon' => "$q"));
$data = $result->fetchAll(PDO::FETCH_ASSOC);
$info = array();
foreach($data as $row) {
$startingdate = $row['startingdate'];
$coupon = $row['coupon'];
$generateddate = $row['coupondate'];
$cWeb = $row['customer_name'];
$receipt = $row['receipt_no'];
$book = $row['book_no'];
$booking = $row['bookingdate'];
$info[] = array('web' => $cWeb,'rec' =>$receipt,'book' =>$book,'booking' =>$booking,'date' =>$generateddate );
}
echo json_encode($info);
}
?>
You must customize to your solution, see this example:
$coupon = '700,701,702,703';
$startdate = '25-02-2015';
$startdate = date_create("25-02-2015");
$find = '702';
$array_coupon = explode(',', $coupon);
$add = array_search($find, $array_coupon) + 1;
date_add($startdate, date_interval_create_from_date_string("$add Months"));
echo date_format($startdate, 'd-m-Y');
EDIT: In your code should be like this:
<?php
if(!empty($_GET['q'])) {
$db = new PDO('mysql:host=localhost;dbname=circulation_scheme_prepaid', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q = $_GET['q'];
$result = $db->prepare('SELECT * FROM receipt_entry WHERE coupon = :coupon');
$result->execute(array(':coupon' => "$q"));
$data = $result->fetchAll(PDO::FETCH_ASSOC);
$info = array();
foreach($data as $row) {
$startingdate = $row['startingdate'];
$coupon = $row['coupon'];
$generateddate = $row['coupondate'];
$cWeb = $row['customer_name'];
$receipt = $row['receipt_no'];
$book = $row['book_no'];
$booking = $row['bookingdate'];
$startdate = date_create($startingdate);
$find = $_GET['q'];
$array_coupon = explode(',', $coupon);
$add = array_search($find, $array_coupon) + 1;
date_add($startdate, date_interval_create_from_date_string("$add Months"));
echo date_format($startdate, 'd-m-Y');
$info[] = array('web' => $cWeb,'rec' =>$receipt,'book' =>$book,'booking' =>$booking,'date' =>$generateddate );
}
echo json_encode($info);
}
?>
I need some help with JSON and PHP. Here's my code in PHP:
include 'class.Connection.php';
$branch = $_GET["b"];
$records = array();
$sqlNailDisplay = "SELECT NAD_ID FROM tbl_NailArtDesign WHERE NAD_Available = 1";
$query0 = mysql_query($sqlNailDisplay) or die(mysql_error());
while($rSet0 = mysql_fetch_array($query0, MYSQL_BOTH)) {
$actualPrice = 0.00;
$nailart = $rSet0["NAD_ID"];
//please note, { is the ascii code for '{', } is the ascii code for '}', while " is the ascii code for '"'
$mergedData = "{"NAD_ID":"".$nailart."","";
//individual nail art details
$sqlNailArt = "SELECT * FROM tbl_NailArtDesign WHERE NAD_ID = '".$nailart."' AND NAD_Available = 1";
$query1 = mysql_query($sqlNailArt) or die(mysql_error());
while($rSet1 = mysql_fetch_array($query1, MYSQL_BOTH)) {
$NAD_Ext = $rSet1["NAD_Ext"];
$CC_ID = $rSet1["CC_ID"];
$CT_ID = $rSet1["CT_ID"];
$CST_ID = $rSet1["CST_ID"];
if(empty($CST_ID)) {
$CST_ID = "null";
}
$NAD_Descrip = $rSet1["NAD_Descrip"];
$mergedData = $mergedData."NAD_Ext":"".$NAD_Ext."","CC_ID":"".$CC_ID."","CT_ID":"".$CT_ID."","CST_ID":"".$CST_ID."","NAD_Descrip":"".$NAD_Descrip."","";
}
//product used and price details
$sqlProductsUsed = "SELECT PL_ID FROM tbl_ProductUsed WHERE NAD_ID = '".$nailart."'";
$query2 = mysql_query($sqlProductsUsed) or die(mysql_error());
while($rSet2 = mysql_fetch_array($query2, MYSQL_BOTH)) {
$PL_ID = $rSet2["PL_ID"];
$sqlProductPrice = "SELECT PP_Amount FROM tbl_ProductPrice WHERE PL_ID = ".$PL_ID." AND BL_ID = '".$branch."'";
$query3 = mysql_query($sqlProductPrice) or die(mysql_error());
while($rSet3 = mysql_fetch_array($query3, MYSQL_BOTH)) {
$price = number_format($rSet3["PP_Amount"],2);
$actualPrice = number_format($actualPrice + $price,2);
}
$mergedData = $mergedData."PL_ID":"".$PL_ID."","PP_Amount":"".$price."","";
}
$mergedData = $mergedData."NAD_Price":"".$actualPrice.""}";
$records[] = $mergedData;
} mysql_free_result($query0);
echo json_encode($records);
And this is the result I'm getting:
["{"NAD_ID":"ND0001","NAD_Ext":"jpg","CC_ID":"1","CT_ID":"1","CST_ID":"null","NAD_Descrip":"Giving you the aquatic feeling with Turquoise Marble","PL_ID":"1","PP_Amount":"9.00","PL_ID":"2","PP_Amount":"9.10","PL_ID":"3","PP_Amount":"9.00","NAD_Price":"27.10"}","{"NAD_ID":"ND0002","NAD_Ext":"jpg","CC_ID":"1","CT_ID":"1","CST_ID":"null","NAD_Descrip":"Add a twirl in your life with Lavender Twirl","PL_ID":"1","PP_Amount":"9.00","PL_ID":"2","PP_Amount":"9.10","PL_ID":"3","PP_Amount":"9.00","NAD_Price":"27.10"}"]
I need my result to look like this:
[{"NAD_ID":"ND0001","NAD_Ext":"jpg","CC_ID":"1","CT_ID":"1","CST_ID":"null","NAD_Descrip":"Giving you the aquatic feeling with Turquoise Marble","PL_ID":"1","PP_Amount":"9.00","PL_ID":"2","PP_Amount":"9.10","PL_ID":"3","PP_Amount":"9.00","NAD_Price":"27.10"},{"NAD_ID":"ND0002","NAD_Ext":"jpg","CC_ID":"1","CT_ID":"1","CST_ID":"null","NAD_Descrip":"Add a twirl in your life with Lavender Twirl","PL_ID":"1","PP_Amount":"9.00","PL_ID":"2","PP_Amount":"9.10","PL_ID":"3","PP_Amount":"9.00","NAD_Price":"27.10"}]
There an extra double quotes that I need to remove from my output.
["{" , ",*"* , }"]
Please help, I'm already at my limit and I already did searching for this, and I can't seem to get any resolution for this...
Hardcoded method:
$result = "[".substr(json_encode($records), 2, -2)."]";
$result = str_replace('","', ',', $result);