Page 1 of 1

creating temp table from results of 2 static tables

Posted: Sun Feb 15, 2004 12:33 pm
by mis2o
hi, i need to create a temporary (mysql) table which contains results from 2 static tables. i use this code, where $_SESSION['query_one'] and $_SESSION['query_two'] contain select query strings for table1 and table2:

Code: Select all

<?php
$joined_query = ($_SESSION['query_one'].";".$_SESSION['query_two']);
$temp_table_query = "CREATE TEMPORARY TABLE tmp $joined_query";
if (!mysql_query($temp_table_query, $connection)) { echo"<script>alert('Query failed')</script>"; }
?>
i always get "Query failed" when executing it, but when i run the $temp_table_query in PHPMyAdmin it works.
what is wrong? can i have 1 temp table containing 2 static tables at all?
if not why does it work in PHPMyAdmin?

i forgot to say that the two static tables have same structure and that i'm using mysql 3.23.47-nt, so i can't use UNION since it is available only in mysql 4 according to the manual.
thanx

Posted: Sun Feb 15, 2004 1:25 pm
by JAM
Just a thought;
Are you using the same username in phpmyadmin as in the script? Setting up phpmyadmin with all privileges contains CREATE. 'Normally' you don't use a username with those privileges when scripting, so the CREATE might be missing...

Posted: Mon Feb 16, 2004 2:00 am
by mis2o
i checked it and privilegies are the same. meanwhile i have changed the code to show mysql_error() and it says i've got error in syntax. it seems it doesn't like those two queries separated by a semicolon(it says "You have an error in your SQL syntax near ';SELECT * FROM rent' at line 1" - queries change according to user's choice in the form). but i need to create a temp table from (the results of) those 2 tables, how can i formulate it in order to work??