Log in

View Full Version : More fetching from tables help


SilverDragonTears
04-30-2012, 05:05 AM
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.

$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.

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


Then simply fetch the property that stores the name.

$getFather->name;

SilverDragonTears
04-30-2012, 02:12 PM
$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

$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