temporary table containing results from 2 static tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

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

temporary table containing results from 2 static tables

Post by mis2o »

hi, i need to create a temporary 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?
thanx
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Are you looking for [mysql_man]UNION[/mysql_man]?
mis2o
Forum Newbie
Posts: 10
Joined: Sat Dec 13, 2003 2:04 pm

Post by mis2o »

i read in mysql manual that UNION is implemented in MySQL 4 only. i use mysql 3.23.39 to develop becouse it runs on the server i write the application for. however, i think that the query1;query2 syntax should work but maybe it doesn't work with CREATE TABLE. don't you know of other way of working it around without using UNION?[/mysql_man]
Post Reply