Warning: Invalid argument supplied for foreach() - help

Discussion regarding Joomla! Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Security and Performance FAQs
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
FDigital01
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 245
Joined: Wed May 11, 2011 7:31 am

Warning: Invalid argument supplied for foreach() - help

Post by FDigital01 » Fri Jan 06, 2012 4:12 am

Warning: Invalid argument supplied for foreach() in /home/globemel/public_html/libraries/joomla/database/database/mysqli.php on line 384


I have started getting this error which is preventing me from updating the database.... can anyone help

adeelkalyami
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Jan 10, 2012 9:58 am

Re: Warning: Invalid argument supplied for foreach() - help

Post by adeelkalyami » Mon Jan 23, 2012 9:44 am

FDigital01 wrote:Warning: Invalid argument supplied for foreach() in /home/globemel/public_html/libraries/joomla/database/database/mysqli.php on line 384


I have started getting this error which is preventing me from updating the database.... can anyone help
You have not declare database variable to null in table class!
just add your database field name and assign it a null value
for example:
var $name = null;

adeelkalyami
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Jan 10, 2012 9:58 am

Re: Warning: Invalid argument supplied for foreach() - help

Post by adeelkalyami » Tue Jan 24, 2012 7:00 am

In view.html.php:
add
global $mainframe; on second line of display function.

in default case:
default:
// Prepare list array
$lists = array();

// Get the user state
$filter_order = $mainframe->getUserStateFromRequest(
$option.'filter_order',
'filter_order', 'published');
$filter_order_Dir = $mainframe->getUserStateFromRequest(
$option.'filter_order_Dir',
'filter_order_Dir', 'ASC');

// Build the list array for use in the layout
$lists['order'] = $filter_order;
$lists['order_Dir'] = $filter_order_Dir;
// Get revues and pagination from the model

// Assign references for the layout to use
$this->assignRef('lists', $lists);

In default.php

add following code instead of: <?php echo JText::_('ID'); ?>
<?php echo JHTML::_('grid.sort', JText::_('ID'), 'id',
$this->lists['order_Dir'],
$this->lists['order'] ); ?>
where JText::_('ID') is the name to display the field.
Id is database field.

At the end, add two hidden fields:
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="" />

In models:

override function _buildQuery() as:
function _buildQuery()
{
$query = ' SELECT * '
. ' FROM #__hello'
. $this->_buildQueryOrderBy();
return $query;
}
function _buildQueryOrderBy()
{
global $mainframe, $option;
// Array of allowable order fields
$orders = array('id', 'name', 'email', 'gender', 'education', 'city', 'date', 'description', 'publish'); //containt name of fields inwhich u want to order you data

// Get the order field and direction, default order field
// is 'ordering', default direction is ascending
$filter_order = $mainframe->getUserStateFromRequest(
$option.'filter_order', 'filter_order', 'id');

// print_r($filter_order); exit;
$filter_order_Dir = strtoupper(
$mainframe->getUserStateFromRequest(
$option.'filter_order_Dir', 'filter_order_Dir', 'ASC'));

// Validate the order direction, must be ASC or DESC
if ($filter_order_Dir != 'ASC' && $filter_order_Dir != 'DESC')
{
$filter_order_Dir = 'ASC';
}

// If order column is unknown use the default
if (!in_array($filter_order, $orders))
{
// $filter_order = 'ordering';
}
$orderby = ' ORDER BY '.$filter_order.' '.$filter_order_Dir;

if ($filter_order != 'ordering')
{
//$orderby .= ' , ordering ';
}
// Return the ORDER BY clause
return $orderby;
}
You do not have the required permissions to view the files attached to this post.

hafizsyrimo
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Nov 03, 2011 4:48 am

Re: Warning: Invalid argument supplied for foreach() - help

Post by hafizsyrimo » Fri Jan 27, 2012 2:32 am

hi...adeelkalyami

i have a same problem with joomla. my site homepage shows:

-Warning: Invalid argument supplied for foreach() in frontpage.php on line 104

-Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in mysql.php on line 344.

i dont have any idea to solved it.

can anyone help me please...

this is urgently..

tq..
Last edited by hafizsyrimo on Fri Jan 27, 2012 8:02 am, edited 2 times in total.

adeelkalyami
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Jan 10, 2012 9:58 am

Re: Warning: Invalid argument supplied for foreach() - help

Post by adeelkalyami » Fri Jan 27, 2012 4:50 am

hafizsyrimo wrote:hi...adeelkalyami

i have a same problem with joomla. my site homepage shows:

-Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/components/com_content/models/frontpage.php on line 104

-Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/libraries/joomla/database/database/mysql.php on line 344.

i dont have any idea to solved it.

can anyone help me please...

this is urgently..

tq..
which version of php you are using ???

hafizsyrimo
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Nov 03, 2011 4:48 am

Re: Warning: Invalid argument supplied for foreach() - help

Post by hafizsyrimo » Tue Jan 31, 2012 2:49 am

i'm using php 5.2.9 on Apache/2.2.11
i'm using joomla 1.5.21


Locked

Return to “Performance - 1.0.x”