Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   More fetching from tables help (http://www.mysidiaadoptables.com/forum/showthread.php?t=3650)

SilverDragonTears 04-30-2012 05:05 AM

More fetching from tables help
 
This snippet of code is suppose to get the names of the parents and show them. As it is now... it shows nothing. I can get it to show the id of the parents, but I'd like it to show their names.

Code:

$result = $adopts->select("owned_adoptables", array(), "aid='{$id}'");
        while ($row = $result->fetchObject()) {
$father=$row->father;
$mother=$row->mother;

$getFather = $adopts->select("owned_adoptables", array(), "aid='{$father}'");
                       
$getMother = $adopts->select("owned_adoptables", array(), "aid='{$mother}'");
$nFather = $row->getFather;
$nFather = $nFather['name'];
$nMother = $row->getMother;
$nMother = $nMother['name'];
if(empty($row->father)) {
    $article_content .= '<b>Caught On:';
} else {
    $article_content .= '<b>Laid On:';
   
}

$article_content .= "{$row->date}<br>";



if($father == '' && $nMother == '') {
    $article_content .= '';
} else {
    $article_content .= 'Father: ' . $nFather . '<br>
                  Mother: ' . $nMother . '<br>';
   
}

}


fadillzzz 04-30-2012 08:00 AM

First, grab the object instance of the result.
PHP Code:

$getFather $adopts->select("owned_adoptables", array(), "aid='{$father}'")->fetchObject(); 

Then simply fetch the property that stores the name.
PHP Code:

$getFather->name


SilverDragonTears 04-30-2012 02:12 PM

Code:

$result = $adopts->select("owned_adoptables", array(), "aid='{$id}'");
        while ($row = $result->fetchObject()) {
$father=$row->father;
$mother=$row->mother;

$getFather = $adopts->select("owned_adoptables", array(), "aid='{$father}'")->fetchObject();
$getFather->name;   
                       
$getMother = $adopts->select("owned_adoptables", array("name"), "aid='{$mother}'");
$nFather = $nFather['name'];
$nMother = $row->getMother;
$nMother = $nMother['name'];


if($father == '' && $nMother == '') {
    $article_content .= '';
} else {
    $article_content .= 'Father: <a href="levelup.php?id='.$father.'">' . $getfather . '</a><br>
                  Mother: ' . $nMother . '<br>';

Somehow I didn't do it right :/

fadillzzz 04-30-2012 02:45 PM

It's like this
PHP Code:

$article_content .= 'Father: <a href="levelup.php?id='.$father.'">' $getFather->name '</a><br>.....'


SilverDragonTears 04-30-2012 03:00 PM

You the MAN!!! Thank you :D


All times are GMT -5. The time now is 06:04 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.