Hi,
I just wondered if you can help me. I have a function which returns an array [syntax=php]<?php function topicname()
{
$querylist = mysql_query("SELECT `topicid`,`topicname` FROM `topiclist`");
$topiclist = array();
while ($listresult = mysql_fetch_assoc($querylist))
{
$topiclist[] = $listresult;
}
return $topiclist;
}
?>[/syntax]
My problem is that when I call the function and feed the array into another function
[syntax=php]$topic = topicname();
print_r($topic);
print_r(forumdetails($topic));[/syntax]
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 [syntax=php] $topicid = (int)$listresult['topicid'];[/syntax] so am not sure why it gives me the error
Undefined index on array output
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: Undefined index on array output
which line is line 14?
-
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: Undefined index on array output
Line 14 was this line [syntax=php] $topicid = (int)$listresult['topicid'];
[/syntax] 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)
[/syntax] 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
[syntax=php]$topicid = (int)$listresult['topicid'];[/syntax]
That's the problem. You are putting the results into the topiclist array in the while loop.
That's the problem. You are putting the results into the topiclist array in the while loop.