Jump to content

My mate sent me this, any ideas?


Nicos Papavasiliou
 Share

Recommended Posts

I want to write this and have $username replaced with the contents of the username field from database1 and "table1_$username" is a table in database2

 

$query = mysql_query("SELECT * FROM table1_$username ORDER BY id DESC") or die(mysql_error());

I tried this during pulling my hair out and I think I am on the right track but can't get it to work. Where am I going wrong?

 

require("config.php");

require("functions.php");

$connection = mysql_connect($host,$usr,$pwd);

mysql_select_db('database1') or die('Cannot select database');

$username = mysql_db_query($db, "SELECT username FROM table_customers where id='$id'", $connection);

 

 

$connection = mysql_connect($host,$usr,$pwd);

mysql_select_db('database2') or die('Cannot select database');

 

$query = mysql_query("SELECT * FROM table1_$username ORDER BY id DESC") or die(mysql_error());

 

but it just doesn't work. I can either get

"Table 'databse2.table1_' doesn't exist "

or

"Table 'databse2.table1_Resource' doesn't exist "

 

 

Anybody?

 

Thanks in advance.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...