Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Fri Jan 28, 2005 9:03 am
or how does it work. i've been searching and searching.
I basically need the output for a query like this (but this one doesn't exist of course):
Code: Select all
SELECT
ID,
naam
FROM
menu_een,
menu_twee
How do I do this?
This is the function I'm using:
Code: Select all
function returnAllMenuItems() {
$sql = "SELECT
ID,
naam
FROM
menu_een,
menu_twee
";
$result = mysql_query($sql);
if (!$result) {
return FALSE;
} else {
$i = 0;
while ($menu = mysql_fetch_array($result)) {
$returnї$i]ї'ID'] = $menuї'ID'];
$returnї$i]ї'naam'] = $menuї'naam'];
}
return $return;
}
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 28, 2005 9:08 am
your query will link together all combinations of ID and naam.. if the field names aren't ambiguous. Is this the intention?
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Fri Jan 28, 2005 9:15 am
basically I need to return all values that are stored in the field "naam" for the tables "menu_een" and "menu_twee".
So if there's "HOME" in menu_een and "LINKS" and "FEATURES" in menu_twee, this query should return:
HOME, LINKS, FEATURES
that's all.
So this would be sufficient I guess:
Code: Select all
SELECT
naam
FROM
menu_een,
menu_twee
Or, maybe it's more clear like this. I want these two queries in only one query:
Last edited by
bytte on Fri Jan 28, 2005 9:17 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 28, 2005 9:17 am
union.
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Fri Jan 28, 2005 9:21 am
Thanks, so this would be the function?
Code: Select all
function returnAllMenuItems() {
$sql = "
(SELECT
ID,
naam
FROM
menu_een)
UNION
(SELECT
ID,
naam
FROM
menu_twee)
";
$result = mysql_query($sql);
if (!$result) {
return FALSE;
} else {
$i = 0;
while ($menu = mysql_fetch_array($result)) {
$returnї$i]ї'ID']= $menuї'ID'];
$returnї$i]ї'naam'] = $menuї'naam'];
}
return $return;
}
}
Or how do I return the values correctly?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 28, 2005 9:22 am
looks correct..
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Fri Jan 28, 2005 9:28 am
Thanks a lot feyd. Again.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 28, 2005 9:31 am
just noticed you don't increment $i...
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Fri Jan 28, 2005 9:45 am
yeah, i noticed it as well... when my browser froze