/    Sign up×
Community /Pin to ProfileBookmark

read two fields as one in mysql table

Hi Guys

Long time no see!! =)

[B]What I have:[/B]
Two date fields in the same table.
eg. “date_field1” and “date_field2” in “mytable”.

None of the dates in and between these to fields are the same.

[B]My Question:[/B]
How do I read the data from these two fields as if it were one field? I want to sort the data in the “combined(for reading)” field ascending.

Thanks for your help.

Ps. I tried UNION, but I get some errors using that..

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Paul_JrAug 18.2004 — If I'm not mistaken, maybe [font=courier]CONCAT()[/font] is what you're looking for?

[code=php]
<?php
$query_date = mysql_query("SELECT CONCAT(date_field, ' ', date_field2) AS date_field FROM table");
$row_date = mysql_fetch_row($query_date);
$date = echo $row_date[0];
?>
[/code]

As far as I know, that will concatenate [font=courier]date_field1[/font] and [font=courier]date_field2[/font] together with a space in the middle and assign it to the alias [font=courier]date_field[/font] (I'm not exactly sure, as I've never used this function before). This might not be what you're looking for, however.
×

Success!

Help @slyfox 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...