Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a master form that allows a user to create a new recipe. The form successfully saves the inputs to the correct database tables.

I have a page with a link to each of the recipes already created. What I need help with now is displaying each recipe's information when that recipe's link is clicked. How do I select the relevant data from ALL of the different tables that the form submitted to?

This is the code that I am working with so far:

<?php
include_once('includes/connection.php');
include_once('includes/recipe.php');
$recipe = new Recipe;

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $basic_data = $recipe->fetch_data($id);

    $sql1 = $pdo->prepare("SELECT recipes.*, categories.* FROM recipes 
      INNER JOIN categories 
      ON (recipes.category_ID = categories.category_ID) 
      WHERE recipes.recipe_id = ?");
    $sql1->bindValue(1, $id);
    $sql1->execute();

    $results1 = $sql1->execute(); 
    echo $results1 = $sql1->fetchAll(PDO::FETCH_ASSOC);
    var_dump($results1);
?>


The code above echos what is shown below, but I have no idea how to use/control that data to echo what I want. In this case, I'm focusing on the category_name. So what I need to have echoed for this specific recipe is 'none' since this recipe is not filed into a specific category.

Arrayarray(1) { [0]=> array(15) { ["recipe_ID"]=> string(1) "1" ["recipe_name"]=> string(20) "English Muffin Pizza" ["category_ID"]=> string(1) "1" ["servings_ID"]=> string(2) "13" ["prep_hours"]=> string(1) "0" ["prep_minutes"]=> string(2) "20" ["cook_hours"]=> string(1) "0" ["cook_minutes"]=> string(2) "10" ["oven_temp"]=> string(3) "350" ["directions"]=> string(402) "These are the directions." ["extra_comments"]=> string(37) "This is a short extra comment." ["recipe_favorite"]=> string(1) "1" ["recipe_photo"]=> string(0) "" ["created"]=> string(19) "2014-09-20 10:22:39" ["category_name"]=> string(4) "none" } }


Please let me know if I can supply you with any other information. I'm at my wits end here and I've been working on this all day. I'm pretty much stuck at this point, so I'm coming in here with an open mind!
Posted
Comments
ChauhanAjay 25-Sep-14 23:55pm    
You could use it this way
Category Name :
in your html portion of the page.

To display your category name. In the similar manner you can use the method to display other items too.

Hope I understood your question in a correct manner.
Member 11110645 26-Sep-14 9:26am    
it worked! thank you!!
ChauhanAjay 26-Sep-14 10:03am    
I have put the above lines in the solution can you kindly accept the solution as solved.

Thanks.

1 solution

You could use it this way
HTML
Category Name : <?php echo $result1["category_name"];??>

in your html portion of the page.

To display your category name. In the similar manner you can use the method to display other items too.

Hope I understood your question in a correct manner.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900