Variable for the field name of mysql row result

Posted by ana on Stack Overflow See other posts from Stack Overflow or by ana
Published on 2012-09-21T21:35:35Z Indexed on 2012/09/21 21:37 UTC
Read the original article Hit count: 393

Filed under:
|
|
|

I'm retrieving a row with php from mysql and it has fields like: name_en, name_es, name_de...

I want to retrieve the right field base on my $lang variable (en, es, de...). If the $lang variable is 'es', I'd need to get $row['name_es'].

I've tried this (based on this thread), but it's not working:

$name = $row->{'name_'.$lang};

Any idea how can I use a variable as the name of the field of a row?

Thanks in advance for your help!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql