Reputation: 97
Let me first start to say my SQL is correct and checked it more than once.
I have 2 methods in my file calling more than once for the SQL but when it comes to the second part it won't return any value to fill in the fields.
Here is the part that is giving me issues:
$query = mysql_query("SELECT * FROM MegaFilter WHERE Parent = '".$ThisPage."' ");
while($query2 = mysql_fetch_assoc($query)) {
$SubID = $query2['Filter'];
$query3 = mysql_query("SELECT * FROM SubCategories WHERE ID = '".$SubID."' ");
while($query4 = mysql_fetch_assoc($query3)) {
$SubCatID = $query4['ID'];
$query5 = mysql_query("SELECT * FROM Web_Pages WHERE SubCat = '".$SubCatID."' ");
}
while($query6 = mysql_fetch_assoc($query5)) {
$ProductName = $query6['Title'];
$ProductID = $query6['ID'];
}
echo '<li class="item" data-id="id-'.$Productid.'" data-type="'.$SubID.'">'.$Productname.'</li>';
}
It does not log any errors except that the last 2 variables are not defined.
Upvotes: 1
Views: 135
Reputation: 60027
I think that the code that you require is (just need the one select statement):
$connection = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$stmt = $connection -> mysqli_prepare('SELECT m.Filter AS SubID, w.Title AS ProductName, w.ID AS ProductID FROM MegaFilter AS m, INNER JOIN SubCategories AS sc ON (sc.ID = m.Filter) INNER JOIN Web_Pages AS w ON (w.SubCat = sc.ID) WHERE Parent = ?');
$stmt->bind_param('s', $ThisPage);
$stmt->bind_result($SubID, $ProductName, $ProductID);
$stmt->execute();
while ($stmt->fetch())
{
echo '<li class="item" data-id="id-'.$ProductID.'" data-type="'.$SubID.'">'.$ProductName.'</li>'
}
Upvotes: 0
Reputation: 4748
Variable names are case sensitive in php. You are assigning values to $ProductName
and $ProductID
but you are using $Productid
(lowercase i) and $Productname
(lowercase n).
Upvotes: 1