Jump to content

Help with displaying data from MYSQL


fludorf

Recommended Posts

Hi all,

 

I am pretty new to the whole php/mysql topic.

 

I am trying to create my own recipe db and I have run into an issue which I cant seem to get around. I am hoping someone can give me to pointers.

 

Basically I would like to display a page which contains recipe details (name, difficulty etc plus the ingredients and procedure).

I the information to display this for a particular recipe is spread over 5 tables:

1. tbl_recipes (high level information about the recipes (name, difficulty, etc)

2. tbl_ingredients (list if all available recipes (id, ingredient name)

3. tbl_x_ingredients (intersection table where I have recipe ID and ingredient ID)

4,5 same idea as 2 and 3 but just for procedure.

 

My first approach was to fire off an sql statement querying the tbl_recipes table and displaying the info on one section of the page. This was ok. The I thought I would simply send a second query displaying all the ingredients for the recipe in a second part or of the page. I ran into issue with this and though using mqsli->multi_query was the solution but also failed to get that working

 

Then I thought I just needed to create a sql statement which has all the results included. However there I got stuck with how to display the data properly. I would get

 

recipe id, name, ingredient

1, pasta, noodles

1, pasta, salt

1, pasta, pepper

 

The problem with this is that I would not know how to parse this result set to display as described above,

 

Any ideas? I would be very grateful of any suggestions.

 

 

 

 

Link to comment
Share on other sites

Hi,

 

what part of it do you not follow?

 

I am trying display data which comes back in to form:

 

recipe id | name | ingredient

----------------------------------

1            | pasta | noodles

1            | pasta | salt

1            | pasta | pepper

 

I would like to display in php:

 

Recipe Name:

Pasta

 

Ingredients:

Noodles

Pepper

Salt

 

I can do the above part easily with something like

 

while($row = mysqli_fetch_assoc($result))

  {

  $title=$row['Title'];

  $difficulty=$row['Difficulty'];

  $time=$row['Time'];

 

Its the lower part that I am lost with.

 

Does this help`?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.