Ok... maybe this is really simple but I've spent almost all day on it, reading the PHP documentation, websites, etc. I am trying to perform a sort of some data from a mysql database, by DATE. However, the original people who made it (and the entire website) were a little dense, and stored the dates as varchar(15) in the format ddmmyy.
I need to retrieve multiple attributes, but sort only by one of the them: con_date.
I have a if(sortby==relevance) ... elseif(sortby==age) condition. The relevance sort isn't a problem. It loops through the array and echos out (in relevance order) a headline, text, and the date in a readable format using a function that converts it:
... then where required:
$date = (substr($date, 4, 2))."-".(substr($date, 2, 2))."-".(substr($date, 0, 2));
$timestamp = strtotime("$date");
$date = date('F j, Y', $timestamp);
That might be useful to solve the problem of the date sort but personally I don't know how just yet.
$date = $line[con_date];
$newdate = convertDate($date);
Incase anyone is wondering what the SQL query looks like, it's this:
And the elseif condition I'm stuck on:
$query = "SELECT con_id, con_category, con_shorthead, con_shorttext, con_text, con_date, MATCH ";
$query .= "(con_text) AGAINST ('$search_submission') AS score FROM apr_content WHERE MATCH (con_text) AGAINST ('$search_submission') ";
$query .= "LIMIT $limitvalue, $page_item_limit";
$result = mysql_query($query) or die(mysql_error());
// print out results in a table
$line = mysql_fetch_array($result, MYSQL_ASSOC);
I was thinking some implementation of asort, but I'm quite new to array stuff really and I can't quite get anything to work.
Loop through the array converting con_date into an accurate sortable date (yymmdd maybe)..... and then sort all the results by con_date, and echo out? Would it be right to say I needed to "sort a multimensional array by value"? :S
Can't be that hard, surely??
Really, really super thanks for any tips / pointers / help