Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Warning: Invalid argument supplied for foreach()
Old 08-09-2009, 08:10 PM Warning: Invalid argument supplied for foreach()
HighRoller23's Avatar
Skilled Talker

Posts: 67
Trades: 1
cpDynaLinks

When you click on a cat. you get this warning? Can someone tell me how to fix this...?

Warning: Invalid argument supplied for foreach() in /home7/cellmonk/public_html/buygreenguide/category.php on line 125
__________________
Currently Working On:
Please login or register to view this content. Registration is FREE
HighRoller23 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-09-2009, 08:59 PM Re: Warning: Invalid argument supplied for foreach()
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Click on a cat??? I'm not sure what you mean by click but I'm not surprised the cat generates a warning.

Seriously:

This warning means that the argument is not an array. Post your code and someone might be able to help you.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-09-2009, 10:38 PM Re: Warning: Invalid argument supplied for foreach()
HighRoller23's Avatar
Skilled Talker

Posts: 67
Trades: 1
cat = categories

http://www.buygreenguide.com

PHP Code:
<?php
//
// +----------------------------------------------------------------------+
// | cpDynaLinks - Dynamic Links Engine
// | http://www.cplinks.com
// | Full licence details can be found at http://www.cplinks.com
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 CMG Technologies  - http://www.cmgtechnologies.com
// +----------------------------------------------------------------------+
// | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// | CMG Technologies OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
// | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// |
// | THE PROGRAM MAY NOT BE SOLD OR RE-SOLD WITHOUT THE EXPLICIT AND WRITTEN
// | PERMISSION OF CMG TECHNOLOGIES.
// |
// | MODIFIED PROGRAM CODES MAY NOT BE PUBLICISED, DISTRIBUTED OR SOLD IN ANY MANNER.
// +----------------------------------------------------------------------+
// | category.php version history:
// | version 1.0 06/10/2004
// +----------------------------------------------------------------------+
//

function show_category_row $cat$category$directory )
 {
 global 
$db;
 global 
$CONFIG_VAR;
 
$query "SELECT Count(category ) As number_links
    FROM  `mnl_links`
    WHERE sub_category='
$directory'
    AND category='
$cat'";
 
$results $db->get_var $query );
 echo 
"<tr>\n";
 if ( 
$directory == "" )
  {
  echo 
"<td width=\"50%\">&nbsp;</td>\n";
  echo 
"<td width=\"50%\">&nbsp;</td>\n";
  }
 else
  {
  
$url $CONFIG_VAR['website_url'] . "/page/" $cat "/" $directory ".html";
  echo 
"<td width=\"4%\" align=\"left\"><img src=\"" $CONFIG_VAR['website_url'] . "/images/triangle_bullet.gif\" alt=\"\"></td>\n";
  echo 
"<td width=\"96%\" class=\"mnlcategorylist\"><a href=\"" $url "\"><b>" ucwords $category ) . "</b></a> (" $results ")</td>\n";
  }
 echo 
"</tr>\n";
 }

function 
show_category_links $title$url$description )
 {
 echo 
"<tr>\n";
 echo 
"<td class=\"mnllinklist\"><a href=\"" $url "\" target=\"_blank\" class=\"mnllinklist\">" $title "</a><br>";
 echo 
$description;
 echo 
"</td>\n";
 echo 
"</tr>\n";
 }

require ( 
"config.php");
require ( 
"global_config.php");
require ( 
"version.php");
require ( 
"includes/mysql.php" );
require ( 
"includes/common.php");
$category_name ucwords str_replace "_"" "$category ) );
$category_name ucwords str_replace "-"" "$category_name ) );
$type   "sub";
$show_advert true;
$title   $category_name " - " $CONFIG_VAR['website_name'];
$keywords  $category;
$description "This is a list of subjects about " $category_name;
//This creates the page header
require ( "templates/mnl_page_header.php" );
// This creates the start of the main body table
echo "<!-- Start of main body table -->\n\n";
echo 
"<table width=\"" $CONFIG_VAR['body_width_value'] . "\" align=\"" $CONFIG_VAR['main_body_align'] . "\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\" bgcolor=\"#" $CONFIG_VAR['main_body_colour'] . "\">\n";
echo 
"<tr>\n";
//This creates the left hand column
require ( "templates/mnl_left_hand_column.php" );
// This creates the middle table
echo "<!-- Start of middle column -->\n\n";
echo 
"<td valign=\"top\">\n";
// This creates the breadcrumbs
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo 
"<tr>\n";
echo 
"<td class=\"mnlbreadcrumbs\"><a href=\"/\">Home</a> >> " $category_name "</td>\n";
echo 
"</tr>\n";
echo 
"</table>\n";
echo 
"<br>\n";
echo 
"<table width=\"550\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">\n";
echo 
"<tr>\n";
echo 
"<td width=\"250\" valign=\"top\">\n";
echo 
"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
$query "SELECT DISTINCT sub_category
   FROM mnl_categories
   WHERE category='
$category'
   AND approved='yes'"
;
$result  $db->get_results $query );
$num_rows $db->num_rows;
$round  round $num_rows/2);
$count 0;
foreach ( 
$result as $val )
 {
 
// don't build a directory if there is no sub directory for this category
 
if ( $val->sub_category == "" )
  {
  continue;
  }
 
$sub_category str_replace "_"" "$val->sub_category );
 
show_category_row $category$sub_category$val->sub_category );
 
$count++;
 if ( 
$count == $round )
  {
  echo 
"</table>\n";
  echo 
"<td width=\"50\">&nbsp;</td>\n";
  echo 
"<td width=\"250\" valign=\"top\">\n";
  echo 
"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  }
 }
echo 
"</table>\n";
echo 
"</td>\n";
echo 
"</tr>\n";
echo 
"</table>\n";
echo 
"<p>\n";
//show the latest links
$query "SELECT *
   FROM mnl_links
   WHERE approved='yes'
   AND category = '
$category'
   ORDER BY id DESC
   LIMIT 0 , 5"
;
$result  $db->get_results $query );
if ( 
$db->num_rows )
 {
 echo 
"<!-- Start of the latest link tables -->\n\n";
 echo 
"<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">\n";
 echo 
"<tr>\n";
 echo 
"<td class=\"mnlhighlightheading\">The latest " $category_name " links:</td>\n";
 echo 
"</tr>\n";
 echo 
"</table>\n";
 echo 
"<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n";
 foreach ( 
$result as $val)
  {
  
$strlength 70;
  
$description strip_slashes $val->description );
  if ( 
strlen $description ) > $strlength )
   {
   
$description substr $val->description0$strlength ) . "...";
   }
  
show_category_links $val->title$val->url$description$val->category );
  }
 echo 
"</table>\n";
 }

//This creates the search form
search_form "sub" );
//This creates the main menu along the bottom of the main column
navigation"sub"$category"" );
echo 
"</td>\n";
echo 
"<!-- End of the middle_column -->\n\n";
// This creates the right hand menu column
require ( "templates/mnl_right_hand_column.php" );

// This ends the main body table
echo "</tr>\n";
echo 
"</table>\n";
//This creates the page footer
require ( "templates/mnl_page_footer.php" );
?>
__________________
Currently Working On:
Please login or register to view this content. Registration is FREE
HighRoller23 is offline
Reply With Quote
View Public Profile
 
Old 08-10-2009, 01:51 AM Re: Warning: Invalid argument supplied for foreach()
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I see 2 foreach loops in the code. The code itself looks fine, each foreach loops through the result of a SQL query. The error may be in the database, make sure that the SQL queries are valid and returning at least one row.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Warning: Invalid argument supplied for foreach()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13682 seconds with 12 queries