switch ($this->table)
{
case 'BS_category_description': //retrieves category ids based on category name ($src_term) taken from form
$this->sql='SELECT `category_id` FROM `' . $this->table . '` WHERE `name`="' . $src_term . '"';
$res = mysqli_query($this->conn,$this->sql);
if($res->num_rows == 0)
{
echo 'No results found, please check your search terms';
exit();
}
while($cRow = mysqli_fetch_array($res)) // retrieves product ids that use the category id retrieved above
{
$this->sqlProd='SELECT `product_id` FROM `BS_product_to_category` WHERE `category_id`=' . $cRow[0];
$resProd = mysqli_query($this->conn,$this->sqlProd);
while($prodRow = mysqli_fetch_array($resProd))
{
$this->id_arr = array_merge ($prodRow, $this->id_arr);
}
}
$this->id_arr=array_unique($this->id_arr);
asort ($this->id_arr);
}
What the above code is intended to do is take a category id and get the product ids that use that category id and put that information into an array $this->id_arr.
Here is the printed out $id_arr:
Array ( [8] => 204 [7] => 205 [6] => 206 [5] => 207 [4] => 208 [3] => 209 [product_id] => 223 [1] => 224 [0] => 225 )
I use the following code to retrieve information from the database based on those ids.
$i = count ($this->id_arr);
for ($a=0; $a < $i; ++$a)
{
$output .= '<tr>';
$this->sql='SELECT model, sku, quantity, image, shipping, price, weight, length, width, height FROM BS_product WHERE product_id='. $this->id_arr[$a];
echo $this->sql . '<br />';
$res = mysqli_query($this->conn, $this->sql);
while($this->sqlOut = mysqli_fetch_array($res))
{
echo $this->sqlOut['model'] . '<br />';
}
$output .= '</tr>';
}
The problem arises when it reaches the the key that should be a 2, but says product id. Anyone know why product_id is being put in for the key instead of a 2?