You are required to register before you can post. This is via a custom verification system. Please post any problems you are encountering here and I`ll do my best to respond as soon as I can. Please note that a reply WILL be posted to all queries, so do not double post. There are no guarantees
when a reply will appear but I do my best to answer all within 3/4 days max. Bumping topics won`t make the slightest difference.
IMPORTANT: Posts in English ONLY please, thank you! Any other languages will be ignored and your message deleted.
SEARCH: Use the search option to see if your question has been answered on the forum before. Or check the relevant script docs.
CUSTOMER: If you have purchased a commercial version of any of my software, using the contact option at the licence centre ensures a faster response.
AUTO DELETION: Accounts older than 5 days, with no posts or topics, are automatically deleted. Only register if you are thinking of posting.
PRIVATE MESSAGES: Private messages are currently disabled.
LINKS: Any links posted are 'NOFOLLOW' and will not be picked up by search engines.
You are not logged in.
Pages: 1
Hi all,
Anybody that has already implemented, or is willing to help me in implementing a 'recipe of the day' on the front side?
The idea is to pick up a randomly recipe from the database and put the title, and a possible image on the front side. Clicking on it (image or title) would forward the user to the recipe.
I have no clue how to implement it as I'm completely a PHP noob!
Any volunteers?
KR; Lecra
Last edited by lecra (21-03-2012 10:17:58)
Offline
Hi Lecra,
This isn`t so difficult, so here goes:
1. First you need to get a random recipe:
$q = mysql_query("SELECT * FROM mr_recipes WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
So, the $RECIPE object now holds the info you need. Title would be:
<?php
echo $RECIPE->name;
?>
2. Next grab an image. You can do random for that too if there are more than 1:
$q2 = mysql_query("SELECT * FROM mr_pictures WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
3. Display image:
<img src="templates/images/recipes/<?php echo $IMG->picPath; ?>" alt="" title="" />
Try that. I`ll leave you to the design part of things.
Offline
This gives me an idea.
What if we want the same image to stay for one day, when we refresh the page, will the image/recipe change as well?
Offline
Its always random above. To have the same don`t use random.
Offline
Pages: 1