public function load($iUserID) { $connection = new Connection(); $sSQL = "SELECT UserID, FirstName, LastName, Username, Address, Email, Telephone, Password, Admin\n FROM tbuser\n WHERE UserID=" . $iUserID; $resultSet = $connection->query($sSQL); $row = $connection->fetch_array($resultSet); //store data into attributes: $this->iUserID = $row['UserID']; $this->sFirstName = $row['FirstName']; $this->sLastName = $row['LastName']; $this->sUsername = $row['Username']; $this->sAddress = $row['Address']; $this->sEmail = $row['Email']; $this->iTelephone = $row['Telephone']; $this->sPassword = $row['Password']; $this->iAdmin = $row['Admin']; // get all recipe ids of each user: $sSQL = "SELECT RecipeID\n FROM tbrecipe\n WHERE UserID=" . $iUserID; $resultSet = $connection->query($sSQL); while ($row = $connection->fetch_array($resultSet)) { $iRecipeID = $row["RecipeID"]; $oRecipe = new Recipe(); $oRecipe->load($iRecipeID); $this->aRecipes[] = $oRecipe; } $connection->close_connection(); }
public static function getAllRecipes() { $aAllRecipes = array(); $connection = new Connection(); $sSQL = "SELECT RecipeID\n FROM tbrecipe\n ORDER BY CreatedAt DESC\n "; $resultSet = $connection->query($sSQL); while ($row = $connection->fetch_array($resultSet)) { $iRecipeID = $row['RecipeID']; $oRecipe = new Recipe(); $oRecipe->load($iRecipeID); $aAllRecipes[] = $oRecipe; } $connection->close_connection(); return $aAllRecipes; }
public function load($iRecipeTypeID) { $connection = new Connection(); $sSQL = "SELECT RecipeTypeID, TypeName, Description, DisplayOrder\n FROM tbrecipetype\n WHERE RecipeTypeID=" . $iRecipeTypeID; $resultSet = $connection->query($sSQL); $row = $connection->fetch_array($resultSet); //store into data attribues: $this->iRecipeTypeID = $row["RecipeTypeID"]; $this->sTypeName = $row["TypeName"]; $this->sDescription = $row["Description"]; $this->iDisplayOrder = $row["DisplayOrder"]; // get all recipe IDs of type: $sSQL = "SELECT RecipeID\n FROM tbrecipe\n WHERE RecipeTypeID=" . $iRecipeTypeID . "\n ORDER BY CreatedAt DESC"; $resultSet = $connection->query($sSQL); while ($row = $connection->fetch_array($resultSet)) { $iRecipeID = $row['RecipeID']; $oRecipe = new Recipe(); $oRecipe->load($iRecipeID); $this->aRecipes[] = $oRecipe; } $connection->close_connection(); }
<?php require_once "includes/header.php"; require_once "includes/recipe.php"; require_once "includes/recipeType.php"; require_once "includes/form.php"; if (isset($_SESSION["UserID"]) == false) { header("Location: loginSignUp.php"); exit; } $iRecipeID = 1; if (isset($_GET["RecipeID"])) { $iRecipeID = $_GET["RecipeID"]; } $oRecipe = new Recipe(); $oRecipe->load($iRecipeID); $aExistingData = array(); $aExistingData["recipeTitle"] = $oRecipe->title; $aExistingData["authorNotes"] = $oRecipe->authorNotes; $aExistingData["ingredients"] = $oRecipe->ingredients; $aExistingData["directions"] = $oRecipe->directions; $aExistingData["recipeCategory"] = $oRecipe->recipeTypeID; // edit recipe $oEditForm = new Form(); $oEditForm->data = $aExistingData; if (isset($_POST["update"])) { $oEditForm->data = $_POST; $oEditForm->files = $_FILES; //form validation $oEditForm->checkFilled("recipeTitle"); $oEditForm->checkFilled("authorNotes");