Hey working on a small project but I seem to be having a problem with a specific part of my code.
The first part works beautifully and displays products within a product category. http://mkiddr.com/phptests/shopping/category.php?id=2
However the issue seems to be having the category description to show, which is derived from a separate query into its own array. I have used
echo(mysqli_num_rows($result2));
This seems to count the correct amounts of rows from the query, indicating the SQL is working perfectly.
I would appreciate help on this I am a complete needbe and I have patched and edited this code to my needs (supplied by university). P.S I am aware there are vulnerabilities within security.
<?php
session_start();
include "conn.php";
include "header.php";
if (isset($_GET['id'])){
$CategoryID = $_GET['id'];
$q="SELECT ProductID, ProductName FROM Products WHERE CategoryID=$CategoryID";
$d="SELECT `Desc` FROM ProductCategories WHERE CategoryID=$CategoryID";
$result = mysqli_query($_SESSION['conn'],$q);
$result2 = mysqli_query($_SESSION['conn'],$d) or die(mysql_error());
echo "<div>";
while ($row = mysqli_fetch_row($result)){
echo "<p><a href='product.php?id=".$row[0]."'>".$row[1]."</a></p>";
}
echo "</div>";
mysqli_free_result($result);
//Description
echo(mysqli_num_rows($result2)); //Test SQL
echo "<div>";
while ($myResult = mysqli_fetch_assoc($result2)){
echo "<p>".$myResult[0]."</p>";
}
echo "</div>";
}
include "footer.php";
?>