编辑: H3>
我已经尝试加入表格,在php中使用strtotime对它们进行排序..但我似乎无法获得语法。玩这个代码..但它变得非常复杂,我希望我可以在纯SQL中更容易。它不完整,但是..你可以看到我在想什么。
mysql_connect("localhost","root","");
mysql_select_db("project");
$SSN = utf8_decode(strip_tags($_GET['ssn']));
//firstname,lastname, email, phone, address, zipcode, district
$result = mysql_query("SELECT *
FROM CARS
WHERE CARS.SSN = '$SSN'");
$result2 = mysql_query("SELECT *
FROM ELECTRONICS
WHERE ELECTRONICS s.SSN = '$SSN'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($obj = mysql_fetch_object($result)) {
$arr[] = $obj;
}
echo '{"users":'.json_encode($arr).'}';
if (!$result2) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($obj = mysql_fetch_object($result2)) {
$arr[] = $obj;
}
echo '{"users":'.json_encode($arr).'}';
function mysort($a, $b) {
return(strtotime($b['datePosted']) - strtotime($a['datePosted']));
}
// pre-sort:
echo "
Before:\n";
print_r($arr);
// do the sort:
usort($arr, 'mysort');
// show the result:
echo "After:\n";
print_r($arr);
echo "
";?>