我在此表中有一个表$sql = "SELECT * FROM upevents ORDER BY ABS(DATEDIFF(NOW(), 'StartDate')) LIMIT 3";
属性:
我需要选择并显示3个事件,这些事件的日期最接近今天。
例如今天的日期是2016年3月8日,所以我需要显示第3个,第4个和第5个。
考试日期:第一个活动开始日期-2/26/2015
考试日期:第二个赛事开始日期-2/25/2015
考试日期:第3次活动开始日期3/10/2016
考试日期:第4个活动开始日期3/12/2016
考试日期:第5个活动开始日期2016年3月19日
package imagedisplay;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
*
* @author D
*/
public class ImageDisplay extends Application {
@Override
public void start(Stage primaryStage) {
Image image1 = new Image("file:lib/1.jpg") ;
Image image2 = new Image("file:lib/2.jpg") ;
ImageView imageView = new ImageView();
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(imageView.imageProperty(), image1)),
new KeyFrame(Duration.seconds(3), new KeyValue(imageView.imageProperty(), image2)),
new KeyFrame(Duration.seconds(5), new KeyValue(imageView.imageProperty(), null))
);
timeline.play();
StackPane root = new StackPane();
root.getChildren().add(imageView);
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
使用上面的选择查询,它显示第1,第2和第3。
答案 0 :(得分:5)
您使用了错误的引号,现在StartDate
被解释为字符串值。
你需要:
$sql = "SELECT * FROM upevents ORDER BY ABS(DATEDIFF(NOW(), `StartDate`)) LIMIT 3";
^ here ^
虽然您不需要在此引用列名称,因为它不是保留字。