-2
Well, I’d like to know how to pull the information from array
from my database, follow as it is in my database:
In short, I’d like to know how I extract this information: {'en' => 'Holiday Promotion', 'en' => 'Vacation Promotion''} when it comes to PHP.
Code you were using to extract from the database:
$stm = $DB->readDB('news', 'WHERE Featured = "yes" ORDER BY ID, RAND() DESC LIMIT 1');
foreach ($stm as $key) {
$title = eval($key['Title'][0]);
$url = $Translate->set('href')['news'].'loja/'.$key['ID'].'-'.$Modulo->tirarAcentos($title, true);
Code you were using to save to the database:
$stm = $DB->createDB('news', 'Title, SubTitle, Category, Message, Featured', '"{'.U_LANG.':'.$title.'}", "{'.U_LANG.':'.$subtitle.'}", $category, $message, "yes"');
return $stm;
This looks like a form, not a database. It would be better to show the SELECT performed, and the raw information.
– Bacco
When you fill out the form with your language, the system automatically translates into languages you add to your website, so when you send it to the database, it sends it as if it were a
dict
, Now I need to extract thisdict
pro site database with PHP, this is what I wish.– user126995
Is and about the
=>
I fixed it, he’s like this now:'pt':'Título'
.– user126995
No, I do not wish to gambiarra, so I came for help, because in
python
i have the script, but I don’t know how to go through php, now help me so if you have the right shape, please.– user126995
Maybe
json_encode
andjson_decode
were better for your case (even so, maybe you still have a better way).json_encode
to transform the array into a textual format, with pairs, andjson_decode
to recover. PHP also hasserialize
andunserialize
– Bacco
I didn’t understand one thing, in your screenshot you have 2 data between { }, but in your save code you have only a couple of name and value. If you’re only gonna get a pair back, you could just do something like
$title= json_decode( $key['Title'] );
so you shall have$title['pt']
being "holiday promotion"– Bacco
Take an example: https://ideone.com/fqM520
– Bacco
Since they invoked the word
gambiarra
nor would it be necessary to change anything at the bank, see https://ideone.com/cw9wuT– user60252
with one more language https://ideone.com/163fCa
– user60252
Leo, if I didn’t ask you too much, could you put the contents of these 3 links in a comic one in an online notebook and send me the link? Why doesn’t my Chrome want to open these links
– user126995
@Akatsuki test on your machine a separate script with these lines:
<?php
|$campo = '{"PT":"o rato","EN":"the mouse"}';
|$array = json_decode($campo, true); // true é array, false é objeto
|print_r($array);
|echo 'Português '.$array["PT"].PHP_EOL;
|echo 'Inglês '.$array["EN"].PHP_EOL;
- is what I had in my IDEONE, is that there you already see the result - remember to break the lines where I put the vertical bar (|)– Bacco
blz Leo, Bacco worked yes this yours getting like this:
Array ( [PT] => o rato [EN] => the mouse ) Português o rato Inglês the mouse
– user126995
Mine is the same thing, Leo made a source of the code I had already sent and added the replace of the
=>
, that’s all.– Bacco
Guys Thanks for everything EVEN, it worked perfectly:
Português: Promoção de Férias
– user126995