Returning an array of objects
Posted: Fri Aug 20, 2010 5:53 pm
I am creating a library that searches and returns information from a huge relational database. I have run into a problem with one of my search functions. I cant seem to get this function to return a proper array of objects:
When I try to access this array of objects I recieve this error: "Fatal error: Call to a member function get_typeName() on a non-object in /BlueprintType_example.php on line 15"
Line 15:
Here is the BlueprintType_example.php
What am I doing wrong?
Code: Select all
public function BlueprintSearch($keyword) {
$db = new EveStaticDb();
$db->connectDb();
$q = "SELECT typeID FROM `invTypes` WHERE typeName LIKE '%".$keyword."%'";
$r = $db->queryDb($q);
$i = 0;
while($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$db->connectDb();
$q1 = "SELECT blueprintTypeID FROM `invBlueprintTypes` WHERE productTypeID LIKE ".$row[typeID];
$r1 = $db->queryDb($q1);
$row1 = mysql_fetch_array($r1, MYSQL_ASSOC);
if($row1[blueprintTypeID] != NULL) {
$bp = new BlueprintType($row1[blueprintTypeID]);
$blueprintResult[$i] = $bp;
$i++;
}
}
return $blueprintResult;
}Line 15:
Code: Select all
echo("<tr><td colspan='4'>".$bpArray->get_typeName()."</td></tr>");Code: Select all
<?php
$searchKey = $_GET[blueprint];
$dbSearch = new SearchDb();
$bpArray = $dbSearch->BlueprintSearch($searchKey);
for($i = 0; $i < count($bpArray); $i++) {
echo("
<table border='1'>
<tr><td colspan='4'>".$bpArray->get_typeName()."</td></tr>
<tr><td>Icons</td>
<td><img src='".$bpArray[$i]->Icon(16)."' />
<td><img src='".$bpArray[$i]->Icon(32)."' />
<td><img src='".$bpArray[$i]->Icon(64)."' />
</tr>
<tr><td>Description</td><td colspan='3'>".$bpArray[$i]->get_description()."</td></tr>
<tr><td>Category</td><td colspan='3'>".$bpArray[$i]->CategoryName()."</td></tr>
<tr><td>Group Name</td><td colspan='3'>".$bpArray[$i]->GroupName()."</td></tr>
<tr><td>Market Group</td><td colspan='3'>".$bpArray[$i]->MarketGroupName()."</td></tr>");
$matList = $bpArray[$i]->get_materialList(); // This function returns an array : $mats[n][typeID][quantity] where n is the total number of mats for that item
$numMats = $bpArray[$i]->get_materialTypeCount();
echo("<tr><th rowspan='".$numMats."' valign='top' align='left'>Mats</th>\n");
for ($i = 0; $i < $numMats; $i++) {
$matItem = new InvType($matList[$i][typeID]);
if($i != 0)
echo("<tr>");
echo("<td>".$matItem->get_typeName()."</td><td colspan='2' align='right'>".$matList[$i][quantity]."</td></tr>\n");
}
echo("</tr>
<tr><td>Base Price</td><td colspan='3'><?php echo($testInv->BasePriceFormatted()); ?></td></tr>
</table>");
}
?>