steviemac Posted March 11, 2007 Share Posted March 11, 2007 Hi, I would like to add an include, or an echo to a query. I have several different files that are selecting from the same table. When I make a new table I have to manually change the table name in each file. I would like to be able to do it once and it will be read by each file. I have tried this $query = "SELECT email_address as email FROM include ['table.php']"; I am getting a syntax error on the include ['table.php']. Any help will be appreciated. Quote Link to comment Share on other sites More sharing options...
Orio Posted March 11, 2007 Share Posted March 11, 2007 Create a file named tablename.php that you will include before creating the query. This file will define a variable/constant and then use it as part of the query. Orio. Quote Link to comment Share on other sites More sharing options...
steviemac Posted March 11, 2007 Author Share Posted March 11, 2007 OK Thanks Quote Link to comment Share on other sites More sharing options...
Orio Posted March 11, 2007 Share Posted March 11, 2007 If you still want to do it your way, create a file that simply contains the table's name without anything else in it and build your query this way: $query = "SELECT email_address as email FROM `".trim(file_get_contents("table-name-file.txt"))."`"; In this example the file was called table-name-file.txt. Orio. Quote Link to comment Share on other sites More sharing options...
steviemac Posted March 11, 2007 Author Share Posted March 11, 2007 I was shown how to "define" so I can use it in a query. That code is this $query = "SELECT email_address as email FROM " .USERS_TABLE; When my query has the table name in the beginning of the query I can not get it to execute in the table i.e. $query = "INSERT INTO IDC (`Course`, `Seats`, `Agency`) "; Is there a different way to input it? I'm still new to PHP MYSQL programing. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.