Calling a Variable within another Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ruthsimon
Forum Newbie
Posts: 19
Joined: Mon Aug 19, 2002 5:44 pm

Calling a Variable within another Variable

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ruthsimon
Forum Newbie
Posts: 19
Joined: Mon Aug 19, 2002 5:44 pm

Post by ruthsimon »

Perfect. Thanks.
Post Reply