This topic is locked
[SOLVED]

 Lookup from another table in view page

2/24/2012 5:46:30 PM
PHPRunner General questions
Z
zephyr325 author

Hello...
I'm trying to use the "Custom" option from the "View As" menu to look up a value from another table. Specifically, my table that the list form is being built from has a column in it that is all numbers - these numbers refer to actual values in a different table.
Table Being Listed
Name

1

2

3

4
Here's the names table I'm trying to reference - a very simple one:

Counter - Name

1 - Tim

2 - Mark

3 - John

4 - Mary
I want the list for this page to show:
Name

Tim

Mark

John

Mary
So I am trying to use php code, but failing:



global $conn;

$str = "select HashName from Hashers where Counter='".$value."'";

$rs = CustomQuery($str);

db_exec($str,$conn);

$value = $rs;


What's the correct syntax to lookup a value from another table based on the $value variable?

C
cgphp 2/24/2012


$rs = CustomQuery("select HashName from Hashers where Counter=".$value." LIMIT 1");

$record = db_fetch_array($rs);

$value = $record['HashName'];
Z
zephyr325 author 2/25/2012




$rs = CustomQuery("select HashName from Hashers where Counter=".$value." LIMIT 1");

$record = db_fetch_array($rs);

$value = $record['HashName'];




Awesome - it works - thanks!