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,686

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: 401

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,686

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: 18

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,686

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: 18

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,686

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: 18

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,686

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: 18

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,686

Re: Recipe of the day

You`re welcome. smile


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

Offline

#13 24-04-2014 21:11:53

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

Re: Recipe of the day

This is a great addition to a recipes site, and I hate to keep asking for help, but how would I go about making it link to the recipe it brings up?  Thanks in advance for any help.  Also, some recipes don't have an image. Is it possible to bring up an alternate image when the recipe does not have one?

Last edited by CrownBBQ (24-04-2014 21:47:54)

Offline

#14 25-04-2014 04:13:07

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

Re: Recipe of the day

CrownBBQ wrote:

This is a great addition to a recipes site, and I hate to keep asking for help, but how would I go about making it link to the recipe it brings up?  Thanks in advance for any help.

Just wrap whatever you need in a <a> tag.

Also, some recipes don't have an image. Is it possible to bring up an alternate image when the recipe does not have one?

Your logic should be....If the query for the image doesn`t find anything, display something else.


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

Offline

#15 25-04-2014 06:43:49

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

Re: Recipe of the day

I was using this snippet from maian cart for a default image if non is found in db. You would need to change the appropriate tags to match your script.

$image  = 'no-thumb-image.jpg';
if ($CATS->imgIcon && file_exists(PATH.'content/products/'.$CATS->imgIcon)) {
$image = $CATS->imgIcon;
}

Offline

#16 25-04-2014 16:28:43

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

Re: Recipe of the day

Thanks

Offline

#17 25-04-2014 22:28:07

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

Re: Recipe of the day

I was able to get the image to show, but the link is giving me all kind of trouble. I know it is something stupid I am leaving out, can one of you folks that are smarter than me look at the code and tell me what I am doing wrong where I am trying to make the recipe a link?  BTW I can't get it to bring up the category, so it will create a link, just not a good one.  Thanks in advance for any help.

<?php
$q = mysql_query("SELECT * FROM crownbbq_recipes WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
echo  $RECIPE->name;
echo "<a href=$CAT->name $RECIPES->name>";
$q2 = mysql_query("SELECT * FROM crownbbq_pictures WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
?>
<img src="templates/images/recipes/<?php echo $IMG->picPath; ?>"WIDTH=282 HEIGHT=180"  onerror="this.src='templates/images/recipes/spices.jpg'" />

</p>

Offline

#18 26-04-2014 05:58:15

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

Re: Recipe of the day

<?php
$q = mysql_query("SELECT * FROM crownbbq_recipes WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
echo  $RECIPE->name;
echo "<br /><a href="?p=recipe&amp;recipe=".$RECIPE->id."">".$RECIPE->name."</a>";
$q2 = mysql_query("SELECT * FROM crownbbq_pictures WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
?>

Think that should be ok.


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

Offline

#19 26-04-2014 12:41:40

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

Re: Recipe of the day

like this takes all the info off the page. Leaves just my header and background. Like maybe I need a closing tag somewhere that it is looking for???   Thanks and sorry to keep asking

Offline

#20 27-04-2014 11:30:28

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

Re: Recipe of the day

Sorry, try:

<?php
$q = mysql_query("SELECT * FROM crownbbq_recipes WHERE enRecipe = 'yes' ORDER BY rand() LIMIT 1");
$RECIPE = mysql_fetch_object($q);
echo  $RECIPE->name;
echo "<br /><a href=\"?p=recipe&amp;recipe=".$RECIPE->id."\">".$RECIPE->name."</a>";
$q2 = mysql_query("SELECT * FROM crownbbq_pictures WHERE recipe = '{$RECIPE->id}' ORDER BY rand() LIMIT 1");
$IMG = mysql_fetch_object($q2);
?>

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

Offline

#21 27-04-2014 11:38:26

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

Re: Recipe of the day

Perfect!!  Thank you for your help and also for your patience.

Offline

#22 27-04-2014 12:16:23

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

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