Jump to content

Drumlegend

Members
  • Posts

    26
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Drumlegend's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Nevermind, the issue has been solved. $recipegallery = mysql_query(" SELECT `id`,`name`, `image`, `description` FROM `recipe` ORDER BY RAND () LIMIT 10; "); The issue was that I needed to add s to $recipegallery
  2. So I am getting this error and I don't understand what I'm doing wrong. PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in \\PDC3\sites\c\cupboard2stomach.com\public_html\index.php on line 102 <?php $recipes = mysql_query(" SELECT `id`,`name`, `image`, `description` FROM `recipe` ORDER BY RAND() LIMIT 4; "); while ($recipe = mysql_fetch_assoc($recipes)) { echo '<section id="recipeslide">'; echo "<a href='php/recipe.php?id=$recipe_id'><img src=\"{$recipe['image']}\" height=100 width=100 /></a><br />"; echo '</section>'; } echo '</section>'; echo '<section id="indexcenter">'; $recipegallery = mysql_query(" SELECT `id`,`name`, `image`, `description` FROM `recipe` ORDER BY RAND () LIMIT 10; "); while ($recipegallery = mysql_fetch_assoc($recipegallery)) { echo '<section id="recipegallery">'; $recipe_id = $recipegallery['id']; echo $recipegallery['name']; echo '<br />'; echo "<a href='php/recipe.php?id=$recipe_id'><img src=\"{$recipegallery['image']}\" height=100 width=100 /></a><br />"; echo '<section id="description">'; echo $recipegallery['description']; echo '</section>'; } echo '</section>'; echo '</section>'; ?> I have two queries running; The first query pulls out 4 random recipes and displays them in a row at the top of the page. The second one is meant to pull 10 random ones out that are display in a main container on the home page but at the moment it's only displaying one recipe and displaying that error. Any thoughts?
  3. I will take this into account once I've stopped pulling my hair out I think I need to do some more reading before I go any further, otherwise I will be stuck on this part for ages. Thank you
  4. So I have changed the form to this. echo '<form action="recipe.php" method="POST">'; echo "<a href='recipe.php?id=" . $recipe['id'] . "'>" . $recipe['name'] . "</a>"; echo '</form>'; There is no longer a button, but when clicking on the link I get this at the top of the url. recipe.php?id= It doesn't seem to be retrieving the ID
  5. I've been working on a project for the past few weeks and it's been a huge learning curve so I apologise in advance. The idea is to choose ingredients and you will retrieve recipes that contain them. Once the results show up the user can click to view in more detail. The user will then be taken to a page which will show the recipe name, image, ingredients and steps of that recipe. That is where I am currently stuck at. These are the results from a search, when you click look you will be directed to this page. I don't know if this is right but this is the what I used for the form action. echo '<form action="recipe.php?id=<?php echo $recipe_id;?>" method="POST">'; echo '<input id="search" name="Look" type="Submit" value="Look" >'; echo '</form>'; On the recipe page I have this php code at the top <?php mysql_connect("10.168.1.56", "cupboard_test", "***") or die("Connection Failed"); mysql_select_db("cupboard_test")or die("Connection Failed"); $result = mysql_query("SELECT `name` FROM `recipe` WHERE `id` = ".$_GET['id']." LIMIT 1"); ?> And I am trying to echo the name further down the page. <?php echo $result['name'].'<br />'; ?> I know I have probably made quite a few mistakes here and I do apologise but it's all part of the learning experience.
  6. The code you posted worked, I just needed to remove public_html from that path that was suggested. Thank you man!
  7. The query runs fine. It pulls out recipes that contain them ingredients. I tried that code and it didn't work. Maybe I have put the wrong path in the database.
  8. Thanks for everyone's help but the million dollar question is how to pull a recipe image that is associated with that recipe. If you check out the site you will understand what I mean. http://www.cupboard2stomach.com/php/get.php This is the php code I have used. $ingredients = array(); //We use an array here to store data as we'll be using the ingredients query data twice, and we can't loop through with mysql_fetch_row twice on the same query $query = mysql_query("SELECT * FROM `ingredients`"); while ($row = mysql_fetch_assoc($query)) { $ingredients[$row['id']] = $row['name']; //now we have all ingredients in an array with the array keys as the ingredient ids and the array values as the names } ?> <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="POST"> <h3> Search your recipe here </h3> <fieldset> Ingredient 1:<select name="dropdown1" id = "drop1"> <?php foreach($ingredients as $id => $name) { ?> <option value="<?php echo $id; ?>"><?php echo $name;?> </option> <?php } ?> </select> Ingredient 2:<select name="dropdown2" id = "drop2"> <?php foreach($ingredients as $id => $name) { ?> <option value="<?php echo $id; ?>"><?php echo $name;?> </option> <?php } ?> </select> Ingredient 3:<select name="dropdown3" id = "drop3"> <?php foreach($ingredients as $id => $name) { ?> <option value="<?php echo $id; ?>"><?php echo $name;?> </option> <?php } ?> </select> <input id="search" name="search" type="Submit" value="Search" > </fieldset> </form> <?php if (isset($_POST['search'])) { $ingredient1 = mysql_real_escape_String ($_POST['dropdown1']); $ingredient2 = mysql_real_escape_String ($_POST['dropdown2']); $ingredient3 = mysql_real_escape_String ($_POST['dropdown3']); $recipes = mysql_query(" SELECT DISTINCT `name`, `step1`, `step2`, `step3`, `image` FROM `recipe` r INNER JOIN `recipe_ingredients` ri ON r.id = ri.recipe_id WHERE ri.ingredient_id IN (".$ingredient1.",".$ingredient2.",".$ingredient3.") "); echo '<section id="results">'; while ($recipe = mysql_fetch_assoc($recipes)) { echo 'Recipe Name: '; echo $recipe['name'].'<br />'; echo '<input id="search" name="Look" type="Submit" value="Search" >'; echo '<br />'; echo 'Step 1: '; echo $recipe['step1'].'<br />'; echo '<br />'; echo 'Step 2: '; echo $recipe['step2'].'<br />'; echo '<br />'; echo 'Step 3: '; echo $recipe['step3'].'<br />'; echo '<br />'; echo $recipe['image'].'<br />'; echo '<br />'; } } echo '</section>'; ?>
  9. I don't know what I type in the image field in the recipe table. I know how to display an image in HTML but I don't need help with that. I need help with the PHP. I can't explain it any clearer.
  10. Basically, I have an image that is associated with a recipe. I have created a field in the recipe table called image which is set as VARCHAR and I don't know what I type in there. I don't know whether I need to put the url there and then I need to know how to retrieve that image and display it on my website. I can't find any tutorials explaining how. I'm sorry if you don't understand the question but I don't think I can explain it any clearer.
  11. How do I store it in the database? Like what path do I type in?
  12. No, it's not hosted online if that's what you mean. It's uploaded to the web server via ftp in a folder called recipeimages.
  13. I have a folder in my ftp called recipeimages and it contains all images for different recipes. In my database I have a recipe table and an image path but I think I may have done it wrong and I was wondering how I would display that image to my webpage. <?php $path = "#"; ?> <img src=<?php echo $src; ?> /> I don't know whether or not this is the correct code I would use. The ideal way would be to display an image assigned to a certain recipe. This is the recipe table, this is probably wrong but you get the idea of what I want to accomplish. This is the table and the fields used. I have the imagepath set as varchar as I don't want to directly store the images in the database. I have never done anything like this before so I would love a bit of help. Thank you in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.