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
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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.