php - Grabbing information from multiple tables -


currently able pull recipe name recipe table want able grab ingredients required ingredients table. know it's joins i'm new joins.

this ingredients table this ingredients table

this recipeingredients table, has 2 primary keys able assign multiple ingredients 1 recipe this recipeingredients table, has 2 primary keys able assign multiple ingredients 1 recipe

this recipe table this recipe table

this search script

<?php     $query = $_get['query'];     // gets value sent on 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 * recipes             (`recipename` '%".$query."%') or (`ingredients` '%".$query."%')") or die(mysql_error());              if(mysql_num_rows($raw_results) > 0){ // if 1 or more rows returned following              while($results = mysql_fetch_array($raw_results)){             // $results = mysql_fetch_array($raw_results) puts data database array, while it's valid loop                  echo "<p>recipe:".$results['recipename']."</p><p>ingredients:".$results['ingredients']."<p>instructions:".$results['instructions']."</p>";                 // posts results gotten database(title , text) can show id ($results['id'])             }          }         else{ // if there no matching rows following             echo "no results";         }      }     else{ // if query length less minimum         echo "minimum length ".$min_length;     } ?> 

ingredients sample data

enter image description here

recipeingredients sample data

enter image description here

recipe table sample data

enter image description here

select     r.*,     i.* recipe r inner join recipeingredients ri     on ri.recipeid = r.recipeid inner join  ingredients     on i.ingredientid = ri.ingredientid r.recipename = 'beans on toast' 

this give recipe , ingrediants.

edits

here how can it.

$query  ="  select                 r.*,                 i.*             recipe r             inner join recipeingredients ri                 on ri.recipeid = r.recipeid             inner join  ingredients                 on i.ingredientid = ri.ingredientid             r.recipename = 'beans on toast'";  $raw_results = mysqli_query($query) or die(mysqli_error());  

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -