/    Sign up×
Community /Pin to ProfileBookmark

Getting results from 2 tables and ordering by timestamp

Hi all,
I am currently having alot of trouble trying to select * from 2 tables and ordering these results via their timestamp.
I have the following table structures:
[B]pm_messages[/B]

[code]
pm_message_id int(10) unsigned NOT NULL auto_increment,
client_id int(10) NOT NULL default ‘0’,
pm_project_id int(10) NOT NULL default ‘0’,
pm_categories_id int(10) NOT NULL default ‘0’,
pm_message_title tinytext NOT NULL,
pm_message_text text NOT NULL,
pm_message_date timestamp(14) NOT NULL,
PRIMARY KEY (pm_message_id)
[/code]

[B]pm_milestones[/B]

[code]
pm_milestone_id int(10) unsigned NOT NULL auto_increment,
pm_project_id int(10) NOT NULL default ‘0’,
pm_milestone_title varchar(255) NOT NULL default ”,
pm_milestone_date date NOT NULL default ‘0000-00-00’,
assigned_group int(10) NOT NULL default ‘0’,
pm_milestone_subdate timestamp(14) NOT NULL,
PRIMARY KEY (pm_milestone_id)
[/code]

And this is my query so far:

[code]
$query_messages_today = mysql_query(“SELECT * FROM pm_messages,pm_milestones WHERE pm_messages.pm_project_id=pm_milestones.pm_project_id AND pm_messages.pm_project_id = ‘” . $_SESSION[‘project_info’][‘2’] . “‘ AND pm_messages.pm_message_date BETWEEN CURDATE() AND NOW()”);
$total_messages = mysql_num_rows($query_messages_today);
[/code]

Any ideas on how i can achieve this?
Cheers,
camcim

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 08.2004 — I think the two tables must be JOINED on a common ID.
×

Success!

Help @camcim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...