Hallo, Gast! (Registrieren)

Letzte Ankündigung: MyBB 1.8.39 veröffentlicht (02.06.25)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
[scheinbar gelöst]Rekursive Funktion mit Rückgabewert
#1
PHP-Code:
function malte($id) {
global
$db, $altbg, $theme, $mybb, $postcounter;
global
$titlescache, $page, $templates, $forumpermissions, $attachcache;
global
$lang, $ismod, $inlinecookie, $inlinecount, $groupscache, $fid;
global
$plugins, $parser, $cache;
$query = $db->query("SELECT `fid` , `pid`
FROM `mybb_forums`
WHERE `fid` ="
.$id."
LIMIT 0 , 1"
);
while(
$forumb = $db->fetch_array($query))
{
if(
$forumb['pid'] == 0)
{
$parent_id = $forumb['fid'];
echo
$parent_id;
return
$parent_id;
}
else
{
echo
'<pre>$forumb'."\n";
print_r ($forumb);
echo
'</pre><hr />';
malte($forumb['pid']);
}
}
}
Wieso bekomm ich mit
PHP-Code:
$query = $db->query("SELECT `tid` , `fid`
FROM `mybb_threads`
WHERE `tid` ="
.$post['tid']."
LIMIT 0 , 1"
);
while(
$thema = $db->fetch_array($query))
{
$bid = malte($thema['fid']);
}

echo
'<pre>Die Rückgabe'."\n";
echo
$bid;
echo
'</pre><hr />';
nur einen Wert, wenn die Funktion nicht rekursiv ist?

//edit
So scheint es zu gehen:

PHP-Code:
/** Unsere Behelfsfunktion für Moderatoren */
function malte($id) {
global
$db, $altbg, $theme, $mybb, $postcounter;
global
$titlescache, $page, $templates, $forumpermissions, $attachcache;
global
$lang, $ismod, $inlinecookie, $inlinecount, $groupscache, $fid;
global
$plugins, $parser, $cache;
$query = $db->query("SELECT `fid` , `pid`
FROM `mybb_forums`
WHERE `fid` ="
.$id."
LIMIT 0 , 1"
);
while(
$forumb = $db->fetch_array($query))
{
if(
$forumb['pid'] == 0)
{
$parent_id = $forumb['fid'];
return
$parent_id;
}
else
{
$parent_id = malte($forumb['pid']);
return
$parent_id;
}
}
}

Zitieren