Maian Script World on Facebook Maian Script World on Twitter Maian Script World - Latest News Tutorial Videos Maian Script World on LinkedIn


Please Read

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.

#1 21-03-2012 10:17:24

lecra
Members
Registered: 13-02-2010
Posts: 33

Recipe of the day

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

#2 22-03-2012 07:31:45

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

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.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

#3 22-03-2012 10:57:43

duceduc
Members
From: Japan
Registered: 25-05-2010
Posts: 382

Re: Recipe of the day

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

#4 22-03-2012 15:45:22

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

Its always random above. To have the same don`t use random.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

#5 11-01-2014 19:27:48

CrownBBQ
Members
Registered: 11-01-2014
Posts: 4

Re: Recipe of the day

First off, I want to say thank you for a great script! My question is..has anyone implemented the Recipe of the Day code above? This seems very useful and I normally don't have alot of trouble with php, but I just cant seem to make it work regardless where I place it in the script, or what I use to open and close the block of code.

Offline

#6 13-01-2014 12:48:48

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

Glad you like it. smile

What happens when you add the code?


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

#7 13-01-2014 16:33:10

CrownBBQ
Members
Registered: 11-01-2014
Posts: 4

Re: Recipe of the day

Thanks for the response. I am trying to add it under the welcome message. Adding it exactly as shown above it just shows the code. When I add the opening and closing <php> it shows nothing at all on the page. I'm sure it is just some little thing I'm not doing.

Offline

#8 15-01-2014 09:15:20

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

Can you post how you are adding the code.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

#9 15-01-2014 13:36:28

CrownBBQ
Members
Registered: 11-01-2014
Posts: 4

Re: Recipe of the day

<p $q = mysql_query("SELECT * FROM ".$database['prefix']." WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
<?php
echo $RECIPE->name;
?>
$q2 = mysql_query("SELECT * FROM ".$database['prefix']." WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
<img src="templates/images/recipes/<?php echo $IMG->picPath; ?>" alt="" title="" />
</p>

Offline

#10 15-01-2014 14:20:01

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

You need to enclose any PHP data in PHP tags.

Also, your table names are missing. ".$database['prefix']." should be your full DB table name:

<p>
<?php
$q = mysql_query("SELECT * FROM mr_recipes WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
echo $RECIPE->name;
$q2 = mysql_query("SELECT * FROM mr_pictures WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
?>
<img src="templates/images/recipes/<?php echo $IMG->picPath; ?>" alt="" title="" />
</p>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

#11 15-01-2014 18:04:01

CrownBBQ
Members
Registered: 11-01-2014
Posts: 4

Re: Recipe of the day

works like a charm, thanks for your help and patience!!

Offline

#12 16-01-2014 07:04:38

msworld
Administrator
From: United Kingdom (Great Britain)
Registered: 09-05-2006
Posts: 7,528

Re: Recipe of the day

You`re welcome. smile


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
David Ian Bennett - Lead Developer
www.maianscriptworld.co.uk

Offline

Board footer

2Checkout.com is an authorized reseller of goods and services provided by Maian Script World.© 2003-2014 David Ian Bennett. All Rights Reserved | Forum: FluxBB

Privacy Policy | Refund Policy