selecting multiple data with query

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
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

selecting multiple data with query

Post by HaVoC »

Code: Select all

<?php
$query = "SELECT * FROM ldu_messanger WHERE message_to = '".$to."' AND message_from = '".$from."' AND message_to = '".$from."' AND message_from = '".$to."' ORDER BY message_id ASC";
?>
That's my query there, what i'm trying to do is have it select messages the person has sent to a certain person, but also display his messages. Is there a way to get 2 different queries in a fetch array?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Code: Select all

<?php
$query = "SELECT * FROM ldu_messanger WHERE (message_to = '".$to."' AND message_from = '".$from."') OR (message_to = '".$from."' AND message_from = '".$to."') ORDER BY message_id ASC";
?>
Image Image
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

yep, phice has posted right solution for your problem, but regarding your exact question:
Is there a way to get 2 different queries in a fetch array?
check mysql manual: http://dev.mysql.com/doc/mysql/en/UNION.html
User avatar
HaVoC
Forum Commoner
Posts: 83
Joined: Sat Feb 07, 2004 7:20 am
Location: Smiths Falls, CA

Post by HaVoC »

Thanks a bunch!
Post Reply