これがどれほど効率的かはわかりませんが、自分でテストできます。ここにあります:
<?php
$sql = 'SELECT timestamp, title FROM news ORDER BY timestamp DESC';
$run = mysql_query( $sql, $link );
$result = array();
if( $run && mysql_num_rows( $run ) ) {
while( ( $fetch = mysql_fetch_assoc( $run ) ) !== false ) {
$time = $fetch[ 'timestamp' ];
$title = htmlspecialchars( $fetch[ 'title' ], ENT_COMPAT, 'UTF-8' );
$result[ $time ][] = $title;
// this is an array, in case multiple title have same timestamp.
}
}
$xml = simplexml_load_file( 'local.xml' );
$xpath = $xml->xpath( '//story' );
foreach( $xpath as $story ) {
$time = $story->time;
$title = (string) $story->headline;
$result[ $time ][] = $title; // append this to the results array.
}
// sort by timestamp ascending
arsort( $result );
?>
それが役に立てば幸い。