Having a problem with this script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
studio727
Forum Newbie
Posts: 2
Joined: Wed Oct 04, 2006 8:57 am

Having a problem with this script

Post by studio727 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am building a link directory for myself to exchange links with everyone, and I downloaded the program, it successfully installed, and it's not working. Do you see what is wrong with the code?


Here's the error:

Code: Select all

Warning: Invalid argument supplied for foreach() in /home/froshizz/public_html/directory/category.php on line 125

Here's the code from line 125 on down:

Code: Select all

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";

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Here's the code from line 125 on down:
interesting, but what is $result? ;)
There's probably some code like $result = xyz();
studio727
Forum Newbie
Posts: 2
Joined: Wed Oct 04, 2006 8:57 am

Post by studio727 »

Code: Select all

$result		= $db->get_results ( $query );
This is what I found
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The error would suggest $result isn't an array. Therefore I can only assume that $db->get_results($query) returned a failure code or something other than an array. var_dump() may be useful here as a debugging helper.
Post Reply