Join in the database

Asked

Viewed 49 times

1

I am developing a software where the user selects the items from his home, selects how long not to clean them, and at the end fills a form to receive a discount by email and clean the items. All this data goes to the bank.inserir a descrição da imagem aqui

However, when doing the Inner Join to display on the front end, the registered item only recognizes the first ID (in this case, id 1)inserir a descrição da imagem aqui

How can I fix this? my tbl_item is:
inserir a descrição da imagem aqui

My sql code is:

SELECT email_cadastrado, nome_cadastrado, nome_item, descricao
FROM tbl_cadastrados c
JOIN tbl_item i ON c.item_cadastrado = i.id_item
JOIN status_cadastrado cad ON c.status_cadastrado = cad.id
where cad.id = 0"
  • John, JOIN won’t go through your field (1,3,4)... The error is probably in your table creation loop. Post to see how is generating the table.

  • In advance before seeing, you will probably have a loop to handle the items within the loop that generates the table.

  • Use this function: http://php.net/manual/en/function.explode.php

  • @Raonibz Warning: explode() expects Parameter 2 to be string, array Given in C: xampp htdocs quiz_Acaro Etapa2.php on line 11

  • i’m treating the variable like this: $checkBoxValue = Join(", ", $_POST['item']); $_SESSION['item'] = $checkBoxValue;

  • You can’t understand with pieces like that. As Luiz said in the answer, the relationship is wrong, but you can do it this way too, you need to see what you find easier. Breaking the field and bringing nomenclature or make ratio from 1 to 1. I think it’s best to post everything as is, there the staff gives you ways to do.

Show 1 more comment

1 answer

2

Your relationship is wrong, the fields of your table "item_registered" should not be like this, it should be a relation N to N with the table of items, having an intermediate table between them, which would have the two id_register values and id item, so your Join would pass by them.

You need to restructure your bank by placing this relational table

Relationship N to N

N:N - The relationship N:N (many-to-many) has a different characteristic from the others. In this case, the data are directly related to the fact, and not the entities, as we observed in the other types of relationships seen previously.

Importantly, there may be no association of facts in situations where relationships are conditional. In this case, the cardinality should be determined by a broad analysis of the possibility of relationships occurring.

Relationship Rules N:N - To establish this type of relationship, we must have three tables, the third one being responsible for relating the other two. For this, these first two tables need to contain a primary key column.

Columns that are primary keys in the first and second table must be columns with a foreign key in the third. Thus, this table will have two foreign keys, which form a composite primary key.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.