By Santiago-1 on
Hi,
I have a table like the following one,
A,aaa
B,bbb
C,ccc
...
Suppose this table is in a database(Postgresql) or in the PHP code (array).
Using this table I would like to generate code like this (as I have many more rows in the original table)
switch($myvar)
{
case "A":
$varname=aaa;
break;
case "B":
$varname=bbb;
case "C":
$varname=ccc;
break;
....
}
I guess I could use a function like for look up in the table, to do the association (e.g. A -> aaa), but don't know which one is available in Drupal ...
What is a common Drupal/PHP strategy to achieve that ?...
Thanks,
Manuel
Comments
... and sorry for my basic
... and sorry for my basic question ...
It depends on how big the
It depends on how big the "table" is, if not too large (you get to decide what that means) you could simple use
You could make $mytable static and place in a function if you need to do the lookup from more than one function.
You could also implement a module that has a *.install file, creates the table and populates it.
Thank you nevets,
I have over 100 rows, although your array code represents an improvement to what I was doing, it's still hardcoding the content into PHP code ...of course you followed my hint of using arrays ...
The other idea of a module sounds interesting, let me see what I could do ...
thank you for your help ...
why not use SQL to do this?
SELECT varname from tablename where key = $myvar
HTH
Terry
Recent Drupal sites:-
www.allegiantair.com www.defaqto.com www.quarkexpeditions.com www.sportrelief.com www.chevronhackles.com
www.philipturnercrafts.co.uk www.intelflexplus.com www.aprilroseturner.com www.businessclubagent.ihg.com www.businessclub.ihg
Of course ...
Really, yes, thank you Terry!