I have a problem with looping through the pulled info form my database (MySQL)
I want to pull all the ID from the Forum table, like this:
SELECT ID FROM Forums
then loop through all the ID’s and run
SELECT ID FROM Catagory WHERE Forum_ID = ?
This is the same in proper php:
$profile=$db->prepare('SELECT ID FROM Forums ');
$profile->execute();
$forums = $profile->fetch();
foreach ($forums as &$forum_ID) {
// some code
$profile=$db->prepare('SELECT ID FROM Catagories WHERE Forum_ID = ?');
$profile->bindValue(1, $forum_ID);
$profile->execute();
$catagories = $profile->fetch();
foreach ($categories as &$category_ID ) {
//some more of my code
}
}
With this code i get an error:
Undefined variable: categories
Please do not mind the spelling errors they are spelled that way in my database, im dyslectic
Thanks in advance
EDIT: For this test i made sure there is something to return by the SQL server
We don’t mind the spelling errors. But PHP minds,
change
$catagoriesinto$categories.