Severity: Notice Message: Undefined variable: data Filename: frontend/v_grafik.php Line Number: 17 - codeigniter-3

CodeIgniter, Message: Undefined variable, Passing data
Controller
function v_grafik() {
// error_reporting(0);
$iklan = $this->Tb_iklan_model->get_all();
$berita = $this->Tb_berita_model->get_all();
$x['data'] = $this->M_grafik->get_data_stok();
if ($x) {
$data = array(
'x' => $x,
'berita' => $berita,
'iklan' => $iklan,
'content' => "frontend/v_grafik",
);
// $content = $this->load->view('frontend/v_grafik',$x);
$this->load->view('layout/frontend', $data);
} else {
$this->session->set_flashdata('message', 'Record Not Found');
redirect(site_url('frontend'));
}
}
View
<?php
foreach($data as $data){
$merk[] = $data->merk;
$stok[] = (float) $data->stok;
}
?>
<canvas id="canvas" width="1000" height="280"></canvas>
<!--Load chart js-->
<script type="text/javascript" src="<?=base_url()?>assets/vendor/chartjs/Chart.js"></script>
<script type="text/javascript" src="<?=base_url()?>assets/vendor/chartjs/Chart.min.js"></script>
<script>
var lineChartData = {
labels : <?php echo json_encode($merk);?>,
datasets : [
{
fillColor: "rgba(60,141,188,0.9)",
strokeColor: "rgba(60,141,188,0.8)",
pointColor: "#3b8bba",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(152,235,239,1)",
data : <?php echo json_encode($stok);?>
}
]
}
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);
</script>
This eror : A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: frontend/v_grafik.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\project\application\views\frontend\v_grafik.php
Line: 17
This Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: frontend/v_grafik.php
Line Number: 17
Can help me?

Why would you do... In your view
foreach($data as $data)
You are changing what $data is and bad things will happen. So you need to change one of them. In this "example" I have changed the 2nd occurrence of $data to $info.
foreach($data as $info){
$merk[] = $info->merk;
$stok[] = (float) $info->stok;
}

Related

overlayMaps and markers in Leaflet

I am using Leaflet to show two sets of markers on a map. Let's call them "trip 1" and "trip 2".
The markers information (lat, lon, description, etc.) is stored in two separate geojson files.
I would like to show each trip separately, using two L.layerGroup, one for each trip.
The code below is the page I have written: so far this is what I have.
The problem is that all markers are already shown on the map before selecting each trip (top right corner - see attached image).
I would like the markers to be shown after selection.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<center>
<div id="map" class="embed-container"></div>
</center>
<script>
var viaggio1 = L.layerGroup([
<?php
$url = 'docs/guardini.geojson'; // path to your JSON file
$dati = file_get_contents($url); // put the contents of the file into a variable
$result = json_decode($dati, true); // decode the JSON feed
$data = $result['features'];
foreach($data as $key => $row) {
$numero = $row['id'];
$nome = $row['name'];
$lat = $row['lat'];
$lon = $row['lon'];
$text = $row['text'];
$pic = $row['pic'];
$link = $row['link'];
?>
L.marker(['<?=$lat;?>', '<?=$lon;?>']),
<?php
}
?>
]);
</script>
<script>
var viaggio2 = L.layerGroup([
<?php
$url2 = 'docs/guardini2.geojson'; // path to your JSON file
$dati2 = file_get_contents($url2); // put the contents of the file into a variable
$result2 = json_decode($dati2, true); // decode the JSON feed
$data2 = $result2['features'];
foreach($data2 as $key2 => $row2) {
$numero2 = $row2['id'];
$nome2 = $row2['name'];
$lat2 = $row2['lat'];
$lon2 = $row2['lon'];
$text2 = $row2['text'];
$pic2 = $row2['pic'];
$link2 = $row2['link'];
?>
L.marker(['<?=$lat2;?>', '<?=$lon2;?>']),
<?php
}
?>
]);
</script>
<script>
var overlayMaps = {
"viaggio 1": viaggio1,
"viaggio 2": viaggio2
};
var map = L.map('map').setView([48.3585, 10.86135], 6);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
attribution: '© OpenStreetMap',
maxZoom: 19,
minZoom: 4
}).addTo(map);
L.control.scale({imperial: false}).addTo(map);
var pol = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
attribution: '© OpenStreetMap',
minZoom: 4,
maxZoom: 19
}).addTo(map);
var sat = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
{
attribution: 'Tiles © Esri — Source: Esri, IGN, IGP, UPR-EGP, and the GIS User Community',
minZoom: 4,
maxZoom: 19
});
var arte = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.{ext}',
{
attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap',
subdomains: 'abcd',
minZoom: 4,
maxZoom: 19,
ext: 'png'
});
var baseMaps = {
"politica": pol,
"satellitare": sat,
"artistica": arte
};
//L.control.layers(baseMaps).addTo(map);
L.control.layers(baseMaps, overlayMaps).addTo(map);
var stile = {
"color": "#ff3385",
"weight": 4,
"opacity": 0.65
};
</script>
<?php
$url = 'docs/guardini.geojson'; // path to your JSON file
$dati = file_get_contents($url); // put the contents of the file into a variable
$result = json_decode($dati, true); // decode the JSON feed
$data = $result['features'];
foreach($data as $key => $row) {
$numero = $row['id'];
$nome = $row['name'];
$lat = $row['lat'];
$lon = $row['lon'];
$text = $row['text'];
$pic = $row['pic'];
$link = $row['link'];
?>
<div id="sidebar<?=$numero;?>" align="left"></div>
<script>
var sidebar<?=$numero;?> = L.control.sidebar('sidebar<?=$numero;?>', {
closeButton: true,
position: 'left'
});
sidebar<?=$numero;?>.setContent('<br>luogo nr. <?=$numero;?><br><br><b><?=$nome;?></b><br><br><?=$text;?><br><br><img src="<?=$pic;?>"><br><br><?=$link;?><br>');
map.addControl(sidebar<?=$numero;?>);
setTimeout(function () {
sidebar<?=$numero;?>.hide();
}, 700);
var marker<?=$numero;?> = L.marker(['<?=$lat;?>', '<?=$lon;?>']).addTo(map).on('click', function () {
sidebar<?=$numero;?>.toggle();
});
</script>
<?php
}
?>
<?php
$url2 = 'docs/guardini2.geojson'; // path to your JSON file
$dati2 = file_get_contents($url2); // put the contents of the file into a variable
$result2 = json_decode($dati2, true); // decode the JSON feed
$data2 = $result2['features'];
foreach($data2 as $key2 => $row2) {
$numero2 = $row2['id'];
$nome2 = $row2['name'];
$lat2 = $row2['lat'];
$lon2 = $row2['lon'];
$text2 = $row2['text'];
$pic2 = $row2['pic'];
$link2 = $row2['link'];
?>
<div id="sidebar<?=$numero2;?>" align="left"></div>
<script>
var sidebar<?=$numero2;?> = L.control.sidebar('sidebar<?=$numero2;?>', {
closeButton: true,
position: 'left'
});
sidebar<?=$numero2;?>.setContent('<br>luogo nr. <?=$numero2;?><br><br><b><?=$nome2;?></b><br><br><?=$text2;?><br><br><img src="<?=$pic2;?>"><br><br><?=$link2;?><br>');
map.addControl(sidebar<?=$numero2;?>);
setTimeout(function () {
sidebar<?=$numero2;?>.hide();
}, 700);
var markerr<?=$numero2;?> = L.marker(['<?=$lat2;?>', '<?=$lon2;?>']).addTo(map).on('click', function () {
sidebar<?=$numero2;?>.toggle();
});
</script>
<?php
}
?>
</div>
</div>
</body>
</html>
It looks like you are adding the markers to the map:
L.marker(['<?=$lat2;?>', '<?=$lon2;?>']).addTo(map)
And I think what you want to do is add the markers to the layerGroups:
L.marker(['<?=$lat2;?>', '<?=$lon2;?>']).addTo(viaggio2)

Google Charts -- Axis Values overlapping and how to avoid

How do I avoid this axis overlap in google charts? I am working with a large data set and not sure what to do to solve this issue. I am using a large number of dates for the x axis. The options I use for my chart are
var options = {
tooltip: {
trigger: 'both',
},
width: 1900,
height: 400,
vAxis: { 'title': 'Volume' },
crosshair: { trigger: 'both'}
};
EDIT::
PHP creation of the containers
if( isset($db_graph_query)){
while($row = mysqli_fetch_array($db_graph_query)) {
$rowcount2++;
// removed the hard coded column set and made it driven off of the array below
// could have pulled it from the $cols array above, but there might be columns that we don't wish to show
echo " <tr>";
$colindex = 0;
foreach( $cols as $column_name ) {
$style = "";
$val = $row[$column_name];
if ( isset($column_callback)) {
$style=$column_callback($colindex, $val);
}
if ($colindex == 0) {
echo "<td style='text-align: left; width: 1pt;'><a href='#' class='toggle' onClick='drawChart(\"$val\");'>$val</a></td>";
$tempval = $val;
} else {
echo "<td $style>$val</td>";
}
$colindex++;
}
echo "</tr>";
echo "<tr class='tablesorter-childRow'>";
echo "<td colspan='12'>";
echo "<div id='$tempval' style='height: 400px;'></div>";
echo "</td>";
echo "</tr>";
}
}
EDIT::
Draw Chart Script, creates the chart options, grabs data from SQL DB and adds into the data:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
function drawChart(inputname) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'RunDate');
data.addColumn('number', 'Runs');
data.addColumn('number', 'Fails');
data.addRows([
<?php
$dbName = "mydb";
$config = parse_ini_file("configfile.ini",true);
$dbUser = $config["DB"]["db_user"];
$dbServer = $config["DB"]["db_ip"];
$dbPassword = $config["DB"]["db_pass"];
$con = mysql_connect($dbServer, $dbUser, $dbPassword);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbName, $con);
$sql = mysql_query("SELECT * From MyTestTable");
$output = array();
while($row = mysql_fetch_array($sql)) {
// create a temp array to hold the data
$temp = array();
// add the data
$temp[] = '"' . $row['Name'] . '"';
$temp[] = '"' . $row['RunDate'] . '"';
$temp[] = (int) $row['Runs'];
$temp[] = (int) $row['FailCount'];
// implode the temp array into a comma-separated list and add to the output array
$output[] = '[' . implode(', ', $temp) . ']';
}
// implode the output into a comma-newline separated list and echo
echo implode(",\n", $output);
mysql_close($con);
?>
]);
var view = new google.visualization.DataView(data);
view.setRows(data.getFilteredRows([
{column: 0, value: inputname}
]));
view.setColumns([1,2,3]);
var options = {
tooltip: {
trigger: 'both',
},
vAxis: { 'title': 'Volume' },
crosshair: { trigger: 'both'},
width: 1900,
height: 400
};
var chart = new google.visualization.LineChart(document.getElementById(inputname));
chart.draw(view, options);
}
</script>
try using option for slanted text...
hAxis: {slantedText: true}
The horizontal axis ticks should not be overlapping at all, and I believe the only way this could be happening is if your chart is not visible at the time you draw it, in which case the chart thinks the ticks don't take up any space and can be packed in as dense as possible. Slanting or alternating would not necessarily help until you get down to the minimum spacing constraint.
So the only real solution, at this time, is to make sure your chart is visible when you draw it.

Missing argument 1 for Illuminate\Support\Manager::createDriver() while sending mail in laravel

my .env file is:
MAIL_DRIVER=mail
MAIL_HOST=smtp.mandrillapp.com
MAIL_PORT=587
MAIL_USERNAME=sabin.maharjan456#gmail.com
MAIL_PASSWORD=****************************
Mailer.php
<?php namespace App\Http\Controllers;
class Mailer{
public function sendTo($email, $subject, $view, $data = array())
{
\Mail::queue($view, $data, function($message) use($email, $subject)
{
$message->to($email)->subject($subject);
});
return "Mail has been sent";
}
public function welcome($formData)
{
$subject = "User Message was arrived !";
$data['name'] = $formData['name'];
$data['email'] = $formData['email'];
$data['mobile'] = $formData['mobile'];
$data['subject'] = $formData['subject'];
$data['bodymessage'] = $formData['message'];
$view = 'emails.welcome';
return $this->sendTo(['sabin.maharjan456#gmail.com'],$subject,$view,$data);
}
}
contoller:
public function postContactFormRequest(CreateContactFormRequest $request,Mailer $mailer)
{
$formData = $request->all();
$this->mailer->welcome($formData);
}
view file:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>User Message</h2>
<p><b>Email Address:</b> {{ $email }}</p>
<h4>User Name : {{ $name }}</h4>
<p> Phone Number :{{ $mobile}}</p>
<p>Message :{{ $bodymessage }} </p>
</body>
</html>
this is my file:
i get a continious error while trying to send email.
Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /home/robustit/public_html/nic-website/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 89 and defined
I have had issues with this until now.
What you want is to check your .env file and make sure your database parameters are right, but also you want these:
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
For some reason I got these to have empty fields. And then it worked for me!

How put dates on flot

I've a little problem, I need to do a curve with on y axis numbers and x axis dates.. but I can't display some dates...
My code :
<script type="text/javascript">
$(function () {
<?php
echo " var data = [";
$cpt="0";
include ('../connect.php');
// Requete SQL
$req = 'select "SPP_NB_IND" from "STAT_PERPHY" where "SPP_SAGES" = \''.$sages.'\' AND "SPP_DATE" between \''.$jourtableau.' 00:00:00\' and \''.$jourfinw.' 23:59:59\'';
$res = pg_query($req);
$reqd = 'select "SPP_DATE" from "STAT_PERPHY" where "SPP_SAGES" = \''.$sages.'\' AND "SPP_DATE" between \''.$jourtableau.' 00:00:00\' and \''.$jourfinw.' 23:59:59\' AND "SPP_NB_IND" IS NOT NULL ';
$resd = pg_query($reqd);
// On met les valeurs obtenues dans un tableau
while ( $row = pg_fetch_assoc ($res) )
{
//echo $row['SPP_NB_IND']."<br>";
$var=$row['SPP_NB_IND'];
while ( $roww = pg_fetch_assoc ($resd) )
{
$abscisse=date('d-m', strtotime($roww['SPP_DATE']));
}
echo "[$abscisse, $var],";
$cpt++;
}
echo "];";
?>
var options = {
lines: {
show: true
},
points: { show: true
},
xaxis: {
mode: "time",
timeformat : "%d/%m"
}
};
<?php
echo "$.plot($(\"#graph1\"), [ data ], options);";
?>
});
</script>
[/CODE]
When I put $abscisse, my curve is vertical and if I put $cpt, I have a "normal" curve... but I want to see dates corresponding with numbers..
Freindly,
Tanaes.
See the documentation:
You have to give flot timestamps, not already formated dates. For PHP use something like
$abscisse = strtotime($roww['SPP_DATE']) * 1000;

jqPlot stackSeries: true, Uncaught TypeError: Cannot read property '0' of undefined

I want to display 3 data series.
Whenever I set the stackSeries: true option in the I get the
Uncaught TypeError: Cannot read property '0' of undefined
or
Uncaught TypeError: Cannot read property '1' of undefined
when trying to display data.
When I remove the stackSeries: true attribue then the chart is rendered. What's wrong?
Update
$(document).ready(function(){
var bar1 = [
<?php
if(!empty($bar1)){
$i = 0;
foreach($bar1 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar1))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
var bar2 = [
<?php
if(!empty($bar2)){
$i = 0;
foreach($bar2 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar2))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
var bar3 = [
<?php
if(!empty($bar3)){
$i = 0;
foreach($bar3 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar3))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
<?php
if(!empty($bar1) && !empty($bar2) && !empty($bar3))
echo 'var labels = ["Bar 1", "Bar 2", "Bar 3"];';
else if(!empty($bar1) && !empty($bar2))
echo 'var labels = ["Bar 1", "Bar 2"];';
else if(!empty($bar2) && !empty($bar3))
echo 'var labels = ["Bar 2", "Bar 3"];';
else if(!empty($bar1) && !empty($bar3))
echo 'var labels = ["Bar 1", "Bar 3"];';
else if(!empty($bar1))
echo 'var labels = ["Bar 1"];';
else if(!empty($bar2))
echo 'var labels = ["Bar 2"];';
else if(!empty($bar3))
echo 'var labels = ["Bar 3"];';
?>
optionsObj = {
//stackSeries: true,
seriesColors:[<?php if(!empty($bar1)) echo '"#4bb2c5",';
if(!empty($bar2)) echo '"#F78181",';
if(!empty($bar3)) echo '"#9AFE2E",';
echo '"#4bb2c5"'; ?>],
animate:true,
legend:{
show:true,
location:"sw",
rowSpacing:"0px",
labels:labels
},
title:{
text:"Jobs",
fontSize:"12px"
},
seriesDefaults:{
showMarker: true,
pointLabels: { show: true },
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barWidth: 2
}
},
axes:{
xaxis:{
pad:1,
tickOptions:{
fontSize:"10px"
},
renderer:$.jqplot.DateAxisRenderer
},
yaxis:{autoscale: true}
},
highlighter: {show: true},
grid:{drawGridlines:true}
};
<?php $empty = false;
if(!empty($bar1) && !empty($bar2) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar1, bar2, bar3], optionsObj);
<?php } else if(!empty($bar1) && !empty($bar2)){ ?>
$.jqplot('chart1', [bar1, bar2], optionsObj);
<?php } else if(!empty($bar2) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar2, bar3], optionsObj);
<?php } else if(!empty($bar1) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar1, bar3], optionsObj);
<?php } else if(!empty($bar1)){ ?>
$.jqplot('chart1', [bar1], optionsObj);
<?php } else if(!empty($bar2)){ ?>
$.jqplot('chart1', [bar2], optionsObj);
<?php } else if(!empty($bar3)){ ?>
$.jqplot('chart1', [bar3], optionsObj);
<?php } ?>
});
I found that if my dataset has discontinuities in it anywhere, then a stacked graph will throw an error.
For example, this data series will throw an error:
[
[[0,22],[1,22],[2,22]],
[[0,33],[2,33]],
]
this one will not:
[
[[0,22],[1,22],[2,22]],
[[0,33],[1,33],[2,33]],
]
Note the difference between the two. The first one doesn't have a data point at X=1 for the second series. The fix would be to make sure all your series have values at all the possible X values, setting any missing ones to zero:
[
[[0,22],[1,22],[2,22]],
[[0,33],[1,0],[2,33]],
]