-2

私は次のようなクエリを持っています:

 select * from posts p where p.post like '%cadillac%' ORDER BY p.upvotes DESC,
 p.unix_timestamp DESC LIMIT 20

ここで、配列をループしながら、最小値を見つける必要がありunix_timestampます。何かのようなもの:

 $counter = 0;
 while($row = $result->fetch_assoc()){

 // what do i do here to find the minimum timestamp value 

 $counter = $counter + 1;
 }

お知らせ下さい。

4

3 に答える 3

2
 $counter = 0;
 $min_timestamp = 0;
 while($row = $result->fetch_assoc()){

     //check if min hasn't been set OR if the current timestamp is less than the min
     if(!$min_timestamp || ($row['unix_timestamp'] < $min_timestamp)) {
         //store this timestamp as the current min
         $min_timestamp = $row['unix_timestamp'];
     } 

     //$counter = $counter + 1;
 }
 //once we reach here, min_timestamp will hold the minimum timestamp found
于 2013-03-25T17:37:07.580 に答える
1

以下が機能します。

$counter = 0;
$min_value;
while($row = $result->fetch_assoc()){
  $min_value = is_null($min_value) || $min_value > $row['unix_timestamp'] ? $row['unix_timestamp'] :$min_value  ;

  $counter = $counter + 1;
}
于 2013-03-25T17:38:48.070 に答える
0

これはSQLで実行できます

select MIN(unix_timestamp) from posts p where p.post like '%cadillac%'
于 2013-03-25T17:36:14.207 に答える