Jump to content

[SOLVED] Add include or echo to a query


steviemac

Recommended Posts

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

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.

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

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.