Drumlegend Posted May 3, 2013 Share Posted May 3, 2013 Currently I am able to pull the recipe name from the recipe table but I want to be able to grab the ingredients required from the ingredients table. I know it's to do with JOINS but I'm new to JOINS. This is the ingredients table This is the recipeingredients table, this has two primary keys so I am able to assign multiple ingredients to one recipe This is the recipe table This is the search script <?php $query = $_GET['query']; // gets value sent over search form $min_length = 3; if(strlen($query) >= $min_length){ $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); // makes sure nobody uses SQL injection $raw_results = mysql_query("SELECT * FROM recipes WHERE (`recipename` LIKE '%".$query."%') OR (`ingredients` LIKE '%".$query."%')") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following while($results = mysql_fetch_array($raw_results)){ // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop echo "<p>Recipe:".$results['recipename']."</p><p>Ingredients:".$results['ingredients']."<p>Instructions:".$results['instructions']."</p>"; // posts results gotten from database(title and text) you can also show id ($results['id']) } } else{ // if there is no matching rows do following echo "No results"; } } else{ // if query length is less than minimum echo "Minimum length is ".$min_length; } ?> This is the sample data from the ingredients table This is the sample data from the recipeingredients table This is sample date from the recipe table Link to comment https://forums.phpfreaks.com/topic/277581-grabbing-information-from-multiple-tables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.