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. Link to comment https://forums.phpfreaks.com/topic/42221-solved-add-include-or-echo-to-a-query/ 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. Link to comment https://forums.phpfreaks.com/topic/42221-solved-add-include-or-echo-to-a-query/#findComment-204810 Share on other sites More sharing options...
steviemac Posted March 11, 2007 Author Share Posted March 11, 2007 OK Thanks Link to comment https://forums.phpfreaks.com/topic/42221-solved-add-include-or-echo-to-a-query/#findComment-204820 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. Link to comment https://forums.phpfreaks.com/topic/42221-solved-add-include-or-echo-to-a-query/#findComment-204821 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 Link to comment https://forums.phpfreaks.com/topic/42221-solved-add-include-or-echo-to-a-query/#findComment-205055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.