Page 1 of 1

Undefined index on array output

Posted: Tue Oct 16, 2012 2:16 pm
by wrichards8
Hi,

I just wondered if you can help me. I have a function which returns an array
<?php function topicname()
{
	$querylist 	= mysql_query("SELECT `topicid`,`topicname` FROM `topiclist`");
	$topiclist 	= array();
	while ($listresult	= mysql_fetch_assoc($querylist))
	{
		$topiclist[] = $listresult;
	}
	return $topiclist;
}
?>
My problem is that when I call the function and feed the array into another function
$topic = topicname();
print_r($topic); 
print_r(forumdetails($topic));
It says Notice: Undefined index: topicid in D:\xamppstuff\htdocs\flamebox\internal\func\forumstuff-inc.php on line 14

I just wondered what I am doing wrong. I have my variable defined as
	$topicid 	= (int)$listresult['topicid'];
so am not sure why it gives me the error

Re: Undefined index on array output

Posted: Tue Oct 16, 2012 4:30 pm
by Temor
which line is line 14?

Re: Undefined index on array output

Posted: Tue Oct 16, 2012 11:00 pm
by wrichards8
Line 14 was this line
        $topicid        = (int)$listresult['topicid'];
but I have changed it so now the value is assigned to a variable which is passed to the other function (so now not using the array as input)

Re: Undefined index on array output

Posted: Wed Oct 17, 2012 6:18 am
by EcazS
$topicid        = (int)$listresult['topicid'];
That's the problem. You are putting the results into the topiclist array in the while loop.