Besides PCs, servers, GNU/Linux, thin clients etc. I do have a vice or two… One is cooking and eating what I cook. Unlike some, I don’t want a recipe to get in my way so I work in the fashion of the “Urban Peasant” and measure little and observe a lot. However, sometimes I want to throw something at someone who asks me for a recipe for what they have just eaten at my table or I want to see how others do things or how to use some ingredient. Books are heavy. Give me data any day.
The Internet is full of old recipes from the MealMaster days (DOS…). There are more than 100K at TheHoseys.com, for instance. There is also a neat programme called “AnyMeal” that comes with Debian GNU/Linux to slurp these up and to create a MySQL database of them.
apt-cache search anymeal -f
Package: anymeal
Priority: optional
Section: kde
Installed-Size: 1488
Maintainer: Sandro Tosi <matrixhasu@gmail.com>
Architecture: i386
Version: 0.30-7
Depends: kdelibs4c2a (>= 4:3.5.9), libc6 (>= 2.7-1), libgcc1 (>= 1:4.1.1-21), libmagic1, libmysqlclient15off (>= 5.0.27-1), libqt3-mt (>= 3:3.3.8b), librecode0 (>= 3.6), libstdc++6 (>= 4.2.1-4), libxalan110, libxerces-c28, docbook-xsl
Filename: pool/main/a/anymeal/anymeal_0.30-7_i386.deb
Size: 468940
Description: A cookbook database for storing recipes
AnyMeal is a Linux recipe database software developed using MySQL and
XML. It can manage a cookbook with more than 100,000 recipes, thereby
allowing to search, display, edit, import and export them. AnyMeal is
designed to be lean and flexible.
Homepage: http://www.wedesoft.demon.co.uk/anymeal-api/
Tag: implemented-in::c++, qa::old-rc-bugs, qa::orphaned, role::program, uitoolkit::qt, use::storing
Working in schools, I feel databases belong on servers and should be accessed by web browsers, so I created an interface to the AnyMeal database in PHP so a simple LAMP server can do the job. Here’s what it looks like:



OK, It’s not pretty. It’s the result that counts… I release this to you under the GPL v3 or Later licence, so you can use, examine, modify, distribute under the same terms, etc. So, you can change it if you want.
Here are the source files. I stripped out all the comments for execution.
searchr.php:
<?php
echo "<html>";
echo "<head><title>Recipe Search by R. Pogson</title></head><body bgcolor=aqua>";
echo "<H1>Robert's Recipe Search</H1>";
echo "<p>Search a database of 150000 recipes for free!\n";
echo "<p>Fill out this form with words and phrases for the title of the recipe and a single word for an ingredient. Use % instead of spaces between words<p>\n";
echo "<form action=\"recipe_search.php\" method=\"post\">";
echo " Title: <input type=\"text\" name=\"query\" ><br >";
echo " Ingredient: <input type=\"text\" name=\"query2\"><br>";
echo " Limit on Hits: <input type=\"text\" name=\"limit\" value=\"50\"><br>";
echo "<p><input type=\"submit\" name=\"submit\" value=\"Submit me!\" ></form></body></html>";
?>
recipe_list.php
<?php
$DatabaseName = "anymeal";
$recipe = htmlspecialchars($_GET['ID']);
echo "<html><head><title>Listing of Recipe</title></head><body bgcolor=aqua>";
echo "ID=".$recipe;
$connection = @mysql_connect("localhost",'squidt5','blue57') or die("<B>Could not connect to
MySQL: </B>".mysql_error());
mysql_select_db($DatabaseName);
$sql = 'SELECT RECIPE.ID,RECIPE.TITLE FROM RECIPE WHERE RECIPE.ID ='.$recipe;
$result = @mysql_query($sql, $connection) or die("<B>(a)Problem reading from
database: </B>".mysql_error());
while ($row = mysql_fetch_array($result))
{
$data=$row['TITLE'];
print "<H1>".$data . "</h1><p>\n";
}
print "<h2>INGREDIENTS</h2><p>\n";
print "\n";
$sql="select NAME,format(AMOUNTNOMINATOR/AMOUNTDENOMINATOR,2) as qty,UNIT,PREP from INGREDIENT,EDIBLE where INGREDIENT.EDIBLEID=EDIBLE.ID AND RECIPEID=".$recipe;
$result = @mysql_query($sql, $connection) or die("<B>(b)Problem reading from
database: </B>".mysql_error());
print "<table border=1><tr><th>Ingredient</th><th>Quantity</th><th>Units</th><th>prep</th></tr>\n";
while ($row = mysql_fetch_array($result))
{
$data="<td>" . $row['NAME']."</td><td> ".$row['qty']." </td><td> ".$row['UNIT']." </td><td> ".$row['PREP'] . "</td>";
print "<tr>" . $data . "</tr>\n";
}
print "</table>\n";
$sql="select INSTRUCTIONS from INSTRUCTIONS where RECIPEID=".$recipe;
$result = @mysql_query($sql, $connection) or die("<B>(c)Problem reading from
database: </B>".mysql_error());
print "<p>\n";
while ($row = mysql_fetch_array($result))
{
$data=$row['INSTRUCTIONS'];
print $data . "</body></html>\n";
}
?>
recipe_search.php
<?php
$DatabaseName = "anymeal";
print "<html><head><title>Recipe Search by R.Pogson</title></head><body bgcolor=aqua>\n";
$connection = @mysql_connect("localhost",'squidt5','blue57') or die("<B>Could not connect to
MySQL: </B>".mysql_error());
$query=$HTTP_POST_VARS['query'];
#echo "Test query=".$query;
$query2=$HTTP_POST_VARS['query2'];
$limit=$HTTP_POST_VARS['limit'];
mysql_select_db($DatabaseName);
$inputvar=substr(htmlentities($query),0,32);
$query=preg_replace('/[^\w\.\-\& ]/', '', $inputvar);
$inputvar=substr(htmlentities($query2),0,32);
$query2=preg_replace('/[^\w\.\-\& ]/', '', $inputvar);
#echo $query;
#echo $query2;
#echo $limit;
if ($query > "")
{if ($query2 > "")
{$sql = 'SELECT distinct `RECIPE`.`ID`, `RECIPE`.`TITLE`'.' FROM RECIPE,EDIBLE,INGREDIENT ' . ' WHERE (`RECIPE`.`TITLE` like \'%' . $query . '%\' AND INGREDIENT.RECIPEID=RECIPE.ID AND EDIBLE.ID=INGREDIENT.EDIBLEID AND EDIBLE.NAME like \'%'.$query2.'%\')' . ' ORDER BY `RECIPE`.`TITLE` ASC';
}
else
{$sql = 'SELECT distinct `RECIPE`.`ID`, `RECIPE`.`TITLE`'.' FROM RECIPE ' . ' WHERE (`RECIPE`.`TITLE` like \'%' . $query . '%\' )' . ' ORDER BY `RECIPE`.`TITLE` ASC';}
}
else
{if ($query2 > "")
{$sql = 'SELECT distinct `RECIPE`.`ID`, `RECIPE`.`TITLE`'.' FROM RECIPE,EDIBLE,INGREDIENT ' . ' WHERE ( INGREDIENT.RECIPEID=RECIPE.ID AND EDIBLE.ID=INGREDIENT.EDIBLEID AND EDIBLE.NAME like \'%'.$query2.'%\')' . ' ORDER BY `RECIPE`.`TITLE` ASC';
}
else
{echo "Nothing to Find. Go Back";$done=true;}
}
if ( $done)
{}
else
{
$sql=$sql." limit 0,".$limit;
$result = @mysql_query($sql, $connection) or die("<B>Problem reading from
database: </B>".mysql_error());
$many=false;
$rownum=0;
while ($row = mysql_fetch_array($result))
{
$rownum=$rownum+1;
$data=$row['ID'] . ' ' . $row['TITLE'];
if ($many) {} else {print "<table><tr><th></th><th><H2>Results</h2></th></tr></table>\n";};
print "<p><tr><td>".$rownum."</td><td> <a href=\"recipe_list.php?";
print "ID=" . $row['ID'] . "\">";
print $data . "</a></td></tr>\n";
$many = true;
}
}
if ($many) {echo "</table>";} else {echo "Nothing Found";};
print "</body></html>";
?>