Aşağıdaki kod azalan "votes_up" ile MySQL veritabanı en iyi 25 girişleri (değişken "site") listeler. Bu harika çalışıyor. Her satır, aşağıdaki yapıya sahiptir "createddatetime" adında bir sütun vardır:
Type: timestamp Default: CURRENT_TIMESTAMP
Nasıl 25 en son eklenen girdileri göstermek için aşağıdaki kodu değiştirebilirsiniz? "1 Kasım 2009 03:45 Greenwich Mean Time": Ayrıca, nasıl böyle damgası görüntüleyebilirsiniz
Teşekkür peşin,
John
mysql_connect("mysqlv8", "username", "password") or die(mysql_error());
mysql_select_db("sitefeather") or die(mysql_error());
$result = mysql_query("SHOW TABLES");
$tables = array();
while ($row = mysql_fetch_assoc($result)) {
$tables[] = '`'.$row["Tables_in_sitefeather"].'`';
}
//$subQuery = "SELECT site, votes_up FROM ".implode(" UNION ALL SELECT site, votes_up FROM ",$tables);
$subQueryParts = array();
foreach($tables as $table)
$subQueryParts[] = "SELECT site, votes_up FROM $table WHERE LENGTH(site)";
$subQuery = implode(" UNION ALL ", $subQueryParts);
// Create one query that gets the data you need
$sqlStr = "SELECT site, sum(votes_up) sumVotesUp
FROM (
".$subQuery." ) subQuery
GROUP BY site ORDER BY sum(votes_up) DESC LIMIT 25";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"samples2\">";
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td class="sitename2"><a href="sitelookup3.php?entry='.urlencode($row["site"]).'&searching=yes&search=search">'.$row["site"].'</a></td>';
echo '<td>'.$row["sumVotesUp"].'</td>';
echo '</tr>';
}
echo "</table>";