For: iamchris
This is it:
$query = "CREATE TEMPORARY TABLE IF NOT EXISTS Table_Name (
col_name1 VARCHAR(15) NOT NULL,
col_name2 VARCHAR(6) NOT NULL,
col_name3 VARCHAR(7) NOT NULL
)";
// Run the query created above on the database through
// the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror();
Understand that you will not be able to see the table from the command line in mysql since manipulating the table or adding contents are restricted to the user who established the connection and created the table (in my case noted by the unique session) and only within the script itself. I suppose you will need a cookie or session as a unique identifier of the user who created the table - but I am not certain.
Understand that my grasp of this subject is not firm, so take the following with a grain of salt: IF NOT EXISTS will prevent the table from being stomped on when you reaccess the script - and prevents an error making it impossible to proceed. You would probably not want the user to be able to CREATE a new table (supposing the other table data used to fill it has been altered) each time the script is accessed after the first instance since it would waste valuable processing time. I'm also not certain IGNORE or REPLACE works with the CREATE TABLE statement.
Therefore, you may need to use a combination of mysql_list_tables and mysql_tablename to determine if the table exists and (if it does) route to a query that INSERTs contents, UPDATEs contents, REPLACEs contents, or ALTERS the table rather than creating it again (you would remove the IF NOT EXISTS in doing this).
Note: After creating the table, you will have to INSERT contents, etc., as well as display results within this script. My question was how to access this table outside the script with the help of sessions, but I have recieved no replies.
If you want to immediately create a table using select column attributes and data contents from another table(s) you can use something like:
$query = "CREATE TEMPORARY TABLE IF NOT EXISTS Table_Name SELECT from Other_Table(s)
col_name1,
col_name2,
col_name3
WHERE col_name1 =\"" . $value1 . "\"
AND col_name2 =\"" . $value2 . "\"
AND col_name3 =\" . $value3 . "\"
GROUP BY col_name1 ORDER BY col_name2";
// Run the query created above on the database through
// the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror();
Hope this helps.