Page 1 of 1

possible or not?: how do I use a variable as a table name

Posted: Tue May 02, 2006 10:54 am
by bradsteele
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to do the following....

pass in a table name, and use it in a select stmt....but it will nt work...is there a syntax error or is this just not possible...

Code: Select all

$_table   =  $_GET["table"];

$_table = $_table . "_admin";

// LOGIN TO THE DATABASE
mysql_connect("localhost", "user", "pass") or die("Cannot connect to DB!");
mysql_select_db("trek") or die("Cannot select DB!");

// GET CLASS LIST
$sql = "SELECT langid FROM '$_table'";
Any help is greatly appreciated,

Brad


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 02, 2006 10:59 am
by feyd
' vs ` issue.

Switch one for the other.

Posted: Tue May 02, 2006 11:02 am
by bradsteele
That did it....thanks.