creating temp table from results of 2 static tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mis2o
Forum Newbie
Posts: 10
Joined: Sat Dec 13, 2003 2:04 pm

creating temp table from results of 2 static tables

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
mis2o
Forum Newbie
Posts: 10
Joined: Sat Dec 13, 2003 2:04 pm

Post 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??
Post Reply