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

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
bradsteele
Forum Newbie
Posts: 15
Joined: Fri Jun 17, 2005 10:27 am

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

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

' vs ` issue.

Switch one for the other.
bradsteele
Forum Newbie
Posts: 15
Joined: Fri Jun 17, 2005 10:27 am

Post by bradsteele »

That did it....thanks.
Post Reply