I have a table of recipes, all have unique id's.
What I'd like to be able to do is to add an article to a separate table, then, below that article on the .php page, display a listing of recipes from the first table that contain a specific keyword, such as 'bacon' to go with the article about bacon.
Is it possible to run an SQL querie in the .php code to display the article AND, have another array below that that displays say, 5 records from the recipe table.
I have a single article.php file that pulls based on the ID in the table containing articles, but not what the article is based on so article.php?id=1 for example, pulls up the bacon article.
How do I make it so that I can also pull up JUST 5 recipes that also contain 'bacon' in their ingredients list?
What is that called? Pulling from 2 different tables based on a specific keyword?
If I need to I can add a category to both tables if that makes it any easier overall to achieve what I need?
This is what I have currently for the article.php page:
Quote:
<?php
$id=intval($_GET['id']);
if($id==0)
{
header( "Location: .404/" ); //or any other page like 404
exit;
}
$pdo=hookitup();
$table = "Articles";
$sql="select * from " . $table . " where ID=" . $pdo->quote($id);
//echo "sql=" . $sql . "<br>";
$stmt=$pdo->query($sql);
//echo "rows back=" . $stmt->rowcount() . "<br>";
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$title = $row['Title'];
$site = "Site Name";
?>
|
Followed by this to display the 5 recipes:
Quote:
<?php
$con=mysqli_connect("localhost","user","pass","db" );
$result = mysqli_query($con,"SELECT * FROM Recipes WHERE Ingredient REGEXP 'bacon ' ORDER BY RAND() LIMIT 5;");
echo "<table border='0'>
<tr>
</tr>";
while($row = mysqli_fetch_array($result))
{
$link = "recipe.php?id=".$row['ID'];
echo "<a class=\"style15\">";
echo " <b><a href=". $link .">". $row['Title'] ."</a></b><br />";
echo "<a class=\"style15\">";
}
echo "</table>";
mysqli_close($con);
?>
|
Is there a way I can use a single mysqli query to show the article AND 5 related recipes?
I was thinking I could use an include but that does not seem to be possible (?)
Any pointers as to what I should be looking into (if even possible) would be appreciated
