0
I have the following SQL table:
|`id` | `user_id` | `key` | `value` | |------------------------------------ | 1 | 1 | nome | João da silva, 50 | 2 | 1 | docs | 552.282.820-58, 22.532.25, 1.230.253-15 | 3 | 1 | cep | 0852-364, 15685-225 | 4 | 2 | nome | Lais dos Santos, 19 | 5 | 2 | docs | 255.365.358-74, 24.582.659, 4.526.874-9 | 6 | 3 | nome | Thais Paula dos Santos, 40, promotora | 7 | 3 | docs | 258.481+574-85, 14.582.478, 3.546.874-8 | 8 | 3 | cep | 05832-005, 04185-007 | 9 | 3 | ende | João Pessoa, 1040, Vila Almeida
I’m trying to make a select but I’m not getting back the values for the key and value column, organized according to the table below:
------------------------------------------------------------------------------------------------------------------ | nome | docs | cep | ende ------------------------------------------------------------------------------------------------------------------ João da silva | 552.282.820-58, 22.532.25, 1.230.253-15 | 0852-364, 15685-225 | Lais dos Santos | 255.365.358-74, 24.582.659, 4.526.874-9 | | Thais Paula dos Santos | 258.481+574-85, 14.582.478, 3.546.874-8 | 05832-005, 04185-007|João Pessoa, 1040, Vila Almeida
my select this way:
$resultado = $pdo->select("SELECT * FROM bd"); foreach ($resultado as $res) { $msg .=" "; $msg .=" ".$res['id'].""; $msg .=" ".$res['user_id'].""; $msg .=" ".$res['key'].""; $msg .=" ".$res['value'].""; $msg .=" "; } echo $msg;
You may not have explained it correctly, but Observer that the key column, it stores the names referring to the columns, and if you notice will notice that the user_id column, the name will repeat itself according to the client id, and the value column stores the data or values. to perhaps facilitate clarification, focus on the user_id, key and value column, and note the second tabelinha there of my question, to see how the result of select should come, it is not the formatting I want, but the header and the body.
– user188807
Brother, you tried to run the code I posted ? What came out ? Logically you should change the name of the query fields and adapt some things as your need. My answer was just a way for you to perform the query and display the data.
– Gato de Schrödinger
got it... the problem is that I’m struggling precisely by bringing these results to php and display, I can’t make it work!
– user188807
When you executed the two codes that I posted, what were the outputs that came out in your file ? Did you make an error or something ? Add more information.
– Gato de Schrödinger
the two ran well, the first was in the format of the table I sent, but the big x of the question for me is the same sort, the header has to be name | Docs | cep | Where , and columns the data of the value column, understood?
– user188807