Page 1 of 1

Calling a Variable within another Variable

Posted: Tue Feb 04, 2003 1:48 pm
by ruthsimon
I have two MySQL tables: Location and Contact. Each have a numeric primary key LocationID and Contact ID. The SQL statement for retrieving record information is identical for each, so instead of repeating my SQL, I set up a quick array.

Code: Select all

$detail = array("Location","Contact");
Now I want to set up my query:

Code: Select all

foreach ($detail as $key => $value) {
  $query = "SELECT * FROM ".$value." WHERE ".$value."ID =$ї$value]ID";
}
The values of $LocationID and $ContactID come from session variables.

What's wrong with the syntax at "=$[$value]ID"??

Thanks, Ruth

Posted: Tue Feb 04, 2003 1:59 pm
by volka

Posted: Tue Feb 04, 2003 2:07 pm
by ruthsimon
Perfect. Thanks.