D4DME – Display Selected Recipe

The final addition that I made to our website was the ability to click on one of the recipe titles and be taken through to a more detailed view of the chosen recipe. To do this, I had to create an id based link to the individual recipe.

<h1>
<a href="selected_recipe.php?recipe_id=<?php echo ($row["recipe_id"]); ?>">
<?php echo ($row["recipe_title"]); ?>
</a>
</h1>

This then linked to the specific recipe page with the corresponding id via this block of code:

<?php
if(isset($_GET["recipe_id"])) {
$recipeID = $_GET["recipe_id"];
} else {
redirectTo("index.php");
}
?>
<br>
<?php 
$result = GetSingleRecipe($recipeID);
while($row = mysqli_fetch_assoc($result)) {
include 'recipe_large.php';
}
?>

As you can see, the include function has changed to include ‘recipe_large.php’ rather than the standard ‘recipe.php’. This file contains more information on the recipe and it much larger in screen size.

Advertisements

D4DME – HTML Forms (Part Four)

Having completed the sign-up form, all I had to do for the next one was tweak a few details.

Untitled

Screenshot of my submit form

The only things that needed to be changed were the names of the fields and certain input options (drop downs rather than text entry). Aside from this, and the change in sql queries, the code was exactly the same.

Note:

The image entry field is currently a text entry because I could not work out how to create an upload query that worked with the dakar server. I managed to make the upload function work, but it told me that I did not have the correct permissions to upload images to the database. So for now, users will have to upload their images using an external image uploader and then paste the URL into the form for it to work (otherwise there is a default image that will display if the field is empty).

Untitled1

Screenshot of my submit form

<?php
        if (!empty($row["recipe_image"])) { 
            $imageName = $row["recipe_image"];
        } else {
            $imageName = "images/Untitled.png";
        }
  	?>
    
<!-- V: The php block above is saying that if the recipe_image column is not empty then to use the URL in it, but if it is empty then use a default image -->
    <img src="<?php echo $imageName; ?>" />

Processing Workshop


Today we had a workshop that introduced us to programming languages. We started off the session by learning a list of keywords (non-specific to Java) and some common misconceptions about programming. We then moved on to a practice session with Java itself. We were basically told that once you know how to write one programming language, you technically known them all (except for the fact that the syntax varies from language to language, just like spoken languages). Learning about the syntax of Java was interesting, as every programming language follows a similar structure but has a unique syntax. We were introduced to a program called ‘Processing’. This program can support Java, JavaScript and Python, though I think we are mostly going to use it for the former of the three.

IMG_20141002_111553765_HDR

Above is a screen shot of part of the work I created today. I understand the basic syntax of Java and how easy it can be to understand, though I am fully aware that it is going to get a lot more complex as we progress. Most of the functions that we used today were called ‘booleans’ and relied on either a true or false outcome in order to perform.

I intend to watch the tutorials on http://www.processing.org/ in order to develop my Java knowledge in my spare time.


Bibliography:

Fry, B. and Reas, C., 2001. Processing [online]. Available from: http://www.processing.org/ [2nd October 2014]