How do I merge two mysql results?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
ShenaCat
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Oct 21, 2002 1:16 pm
Location: Seattle, WA
Contact:

Wed Oct 23, 2002 1:30 pm

So I have two SQL statements in php:

$sql = "SELECT * FROM users WHERE location='$lid'";
$sql2 = "SELECT * FROM admin WHERE location='$lid'";

$result = mysql_query($sql);
$result2 = mysql_query($sql2);

now I want to merge $result and $result2 into one variable so I can work with them together... how can I do that? Are they just regular arrays..? if I merged them together could I then do a mysql_num_rows($merged_var) function on it...?

Thanks
Shena Delian O'Brien

Jay

Thu Oct 24, 2002 1:53 am

Output them into an array first, and then manipulate them from there!

User avatar
ShenaCat
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Oct 21, 2002 1:16 pm
Location: Seattle, WA
Contact:

Thu Oct 24, 2002 2:36 pm

The problem is, that'd be a hell of an array :)

I've decided to use a temporary table and just output what I want from each table into this temporary table and then pull the data from there... it seemed the most expedient method until UNION in mySQL 4.0.0!
Shena Delian O'Brien

User avatar
ShenaCat
New php-forum User
New php-forum User
Posts: 9
Joined: Mon Oct 21, 2002 1:16 pm
Location: Seattle, WA
Contact:

Thu Oct 24, 2002 6:51 pm

I tried that already and it doesn't work, because it puts the results all in one row instead of in multiple rows...?
Shena Delian O'Brien

DoppyNL

Fri Oct 25, 2002 2:25 am

IF in the table `user` users are stored and in the table `admin` administrators, you might want to rethink you're databasestructure...

Personally, I store all users of my site in one table, and use fields to give them certain rights or not.

Greetz Daan

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 2 guests