I'm getting the following error
PHP Notice: Undefined offset: 4 -- LINE 190
in the chunk of code below. I've tried a couple different solutions that I found here including isset, but nothing seems to work.
Does anyone have any suggestions?
// If we don't have any data get it from the db
$GLOBALS['AKB_CLASS_HELPER']->getCatsInfo();
$parentid = 0;
if (!empty($arrCats[0])) {
foreach ($arrCats as $cat) {
foreach ($GLOBALS['AKB_CLASS_HELPER']->tree->nodesByPid[$parentid] as $catid) { <--------- LINE190
$pcat = $GLOBALS['AKB_CLASS_HELPER']->catsById[$catid];
if (strtolower($pcat['name']) == strtolower($cat)) {
$GLOBALS['CatTrails'][] = array ($pcat['categoryid'], $cat);
$this->_catId = $pcat['categoryid'];
$parentid = $pcat['categoryid'];
break;
}
}
}
}
Related
Notice: Undefined index: 9781400108503 in C:\xampp\htdocs\ibshelf.com\cart.php on line 38
Notice: Undefined index: 9781400108503 in C:\xampp\htdocs\ibshelf.com\cart.php on line 42
Warning: array_count_values(): Can only count STRING and INTEGER values! in C:\xampp\htdocs\ibshelf.com\cart.php on line 53
// book_isbn got from form post method
if(isset($_POST['bookisbn'])){
$book_isbn = $_POST['bookisbn'];
}
if(isset($book_isbn))
{
// new item selected
if(!isset($_SESSION['cart']))
{
// $_SESSION['cart'] is associative array that bookisbn => qty
$_SESSION['cart'] = array();
$_SESSION['total_items'] = 0;
$_SESSION['total_price'] = '0.00';
}
if(!isset($_SESSION['cart'][$book_isbn]))
{
$_SESSION['cart'][$book_isbn] = 1;
} elseif(isset($_POST['cart']))
{
$_SESSION['cart'][$book_isbn]++;
unset($_POST);
}
}
// if save change button is clicked , change the qty of each bookisbn
if(isset($_POST['save_change'])){
foreach($_SESSION['cart'] as $isbn =>$qty){
if($_POST[$isbn] == '0')
{
unset($_SESSION['cart']["$isbn"]);
} else {
$_SESSION['cart']["$isbn"] = $_POST["$isbn"];
}
}
}
$title = "Your shopping cart";
if(isset($_SESSION['cart']) && (array_count_values($_SESSION['cart']))){
$_SESSION['total_price'] = total_price($_SESSION['cart']);
$_SESSION['total_items'] = total_items($_SESSION['cart']);
"9781400108503" seems to be the value of $isbn in the for loop on save_change.
On line 42, the notice is triggered for $_POST[$isbn]. Make sure you use isset($_POST[$isbn]). There doesn't seem to be a value posted for this ISBN.
On line 53, you're using array_count_values(). That's not the function you're intending to use. Do count($_SESSION['cart']) instead.
Hi I receive the following error in my homework and I do not know what is the problem hasildata.php on line 21 :
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
Screenshot
You must check whether your request is OK or not
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
if ($data['status'] !== "OK") {
// Error
echo $data['error_message'];
// Do something
} else {
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
}
someone from freelancer created this web based software for us. By mistake i deleted all the medical examination (i'm a doctor assistant) from the control panel.
The software now gives me this error:
Message: Undefined variable: data
Filename: models/gestione_model.php
Line Number: 127
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: models/gestione_model.php
Line Number: 127
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: models/gestione_model.php
Line Number: 127
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: models/gestione_model.php
Line Number: 127
I find the line 27 here:
public function conta_visite($s)
{
$query = $this->db->get('oggetti');
if ($query->num_rows() > 0) {
$data = $query->result_array();
}
$aperte = 0;
$chiuse = 0;
foreach ($data as $d) {
if (new DateTime() > new DateTime($d['DataVisita'])) $chiuse++;
else $aperte++;
}
if($s == 1) return $aperte;
else return $chiuse;
}
Can someone help me please? Thanks
you are closing IF before foreach!
public function conta_visite($s) {
$query = $this->db->get('oggetti');
if ($query->num_rows() > 0) {
$data = $query->result_array();
} // HERE if result is ==0 then $data does not exist
$aperte = 0; $chiuse = 0; foreach ($data as $d) {
if (new DateTime() > new DateTime($d['DataVisita'])) $chiuse++;
else $aperte++;
}
if($s == 1) return $aperte;
else return $chiuse;
You need to make sure that $data is set before using it. If no rows are returned then $data is not set and you get errors when trying to process it.
if ($query->num_rows() > 0) {
$data = $query->result_array();
} else {
//do what needs to be done if the database does not return any rows
$data = array(); //empty array maybe?
}
This is the error found in admin area:
Notice: Undefined index: menu in admin_menu_admin_menu_output_alter()
(line 612 of
/var/www/sites/all/modules/admin_menu/admin_menu.module).
Warning:Invalid argument supplied for foreach() in
admin_menu_admin_menu_output_alter() (line 612 of
/var/www/sites/all/modules/admin_menu/admin_menu.module).
Code is:
/**
* Implements hook_admin_menu_output_alter().
*/
function admin_menu_admin_menu_output_alter(&$content) {
foreach ($content['menu'] as $key => $link) {
// Move local tasks on 'admin' into icon menu.
if ($key == 'admin/tasks' || $key == 'admin/index') {
$content['icon']['icon'][$key] = $link;
unset($content['menu'][$key]);
}
}
}
Foreach is line:612
What is the error in this code?
Thanks in advance.
As the error says, $content['menu'] seems to be undefined, but it should be an array since you are attempting to use foreach on it. Therefore, you would need to do something like this before using it:
$content['menu'] = array('value1', 'value2');
function admin_menu_admin_menu_output_alter(&$content) {
// Check if index menu is defined in $content and is array
if( !isset($content['menu']) || !is_array($content['menu']) )
return;
foreach ($content['menu'] as $key => $link) {
// Move local tasks on 'admin' into icon menu.
if ($key == 'admin/tasks' || $key == 'admin/index') {
$content['icon']['icon'][$key] = $link;
unset($content['menu'][$key]);
}
}
}
When I'm executing this code-
public $speaker_list=array();
for($i=0;$i<$nbre_speaker;$i++)
{
$speaker_list[$i]=new Speaker($_POST['speaker'+$i],$_POST['pro_speaker'+$i],$_POST['bio_speaker'+$i]);
}
I'm getting the error:
Notice: Undefined offset: 0
Notice: Undefined offset: 1
Assuming $nbre_speaker is set to something sensible outside the code you provided.
Try this
public $speaker_list = array();
for($i=0; $i < $nbre_speaker; $i++)
{
if ( isset($_POST['speaker'.$i], $_POST['pro_speaker'.$i], $_POST['bio_speaker'.$i] )) {
$speaker_list[$i] = new Speaker($_POST['speaker'.$i],
$_POST['pro_speaker'.$i],
$_POST['bio_speaker'.$i]);
} else {
// report error, or do something to fix it.
}
}