Jump to content

Using variables in place of table names in query


mcfmullen

Recommended Posts

I have a url that goes as follows:

 

http://www.cool.com/page.php?type=Animal&animal=nameAnimal

 

I have a MySQL query as follows:

 

<?php
$tablename = $_GET['type'];
$animal = $_GET['animal'];

$sql = SELECT * from Animal;

What I want to do is have the query resemble something like:

 

$sql = SELECT * from $tablename;

 

But I am unable to get the proper syntax. Can anyone help me out?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.