Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Problem with UNION in mysql 3.x

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-03, 09:58
segovia6969 segovia6969 is offline
Registered User
 
Join Date: Nov 2003
Posts: 6
Problem with UNION in mysql 3.x

Hi everybody!

I got a big problem with this...
I have this 2 queries ($query1 and $query2):

$query1 = "SELECT Name, Autor, Typ, Dateiname FROM dokumente
WHERE ";
$i = 0;
while ($i<$number) //while there are still array elements to go
{
$query1 .= "$searchtype LIKE '%$splitsearchterm[$i]%' AND ";

$i++; //increment $i
}

#remove the extra " AND" from the end
$query1 = substr($query1,0,-4);

$query2 = "SELECT at.Arbeitsname, ut.Name, at.Type, at.filename
FROM users_table ut, arbeiten_table at
WHERE at.AuthorID=ut.ID AND ";
if ($searchtype==Name)
{
$searchtype=Arbeitsname;
}

else
{
$searchtype=Name;
}

$i = 0;
while ($i<$number) //while there are still array elements to go
{
$query2 .= "$searchtype LIKE '%$splitsearchterm[$i]%' AND ";

$i++; //increment $i
}

#remove the extra " AND" from the end
$query2 = substr($query2,0,-4);

Then I made a UNION of them in mysql 4.x like this and it worked:

$query = "($query1)
UNION
($query2)
ORDER BY Name";

Now I have to change the script for mysql 3.x and I wanted to use the temprary table trick like this:

$query = "CREATE TEMPORARY TABLE temp_union ".$query1."
INSERT INTO temp_union ".$query2."
SELECT * FROM temp_union ORDER BY Name";
DROP TABLE temp_union";

and it didn't work. This is the echo of the query and the error that I get:

CREATE TEMPORARY TABLE temp_union SELECT Name, Autor, Typ, Dateiname FROM dokumente WHERE Name LIKE '%cad%' INSERT INTO temp_union SELECT at.Arbeitsname, ut.Name, at.Type, at.filename FROM users_table ut, arbeiten_table at WHERE at.AuthorID=ut.ID AND Arbeitsname LIKE '%cad%' SELECT * FROM temp_union ORDER BY Name
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /vdsk/projekte.d/DET-wissdb/dokumenten_suche1.php on line 100

Can someone please tell what is wrong with the query?
Why doesn't it work?
Is there any other solution for this?
Thanx for everything!

Greetings,

Nacho.
Reply With Quote
  #2 (permalink)  
Old 12-13-03, 22:17
omiossec omiossec is offline
Registered User
 
Join Date: Jan 2003
Location: Paris, France
Posts: 320
You may use ; or \g to separate your query
__________________
Olivier Miossec
--
http://www.lasso-developpeur.net/
--
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On