2011-04-10 77 views
-5

我需要從名爲wallpaper的表中選擇寬度或高度分辨率的壁紙。我怎樣才能做到這一點?我有:從分辨率選擇寬度或高度

$sql_wallpaper = "SELECT * from wallpaper 
        WHERE height = '1600' ORDER BY RAND() LIMIT 0,3"; 
+2

什麼問題呢? – Flinsch 2011-04-10 17:33:28

+0

我需要選擇1600分辨率的壁紙 – Hassan 2011-04-10 17:37:07

+0

那麼,這應該不成問題!那麼,究竟是什麼問題? – Flinsch 2011-04-10 17:39:22

回答

1

如果你的高度和寬度字段的類型是數字,所以我會救作爲INT的寬度和高度(範圍:-2.147.483.648 - 2.147.483.647,應該足夠了),因爲通常分辨率不會有任何小數,然後嘗試將'1600'作爲字符串,因爲這裏的1600被設置爲單引號標記)而是作爲數字並刪除引號。

所以,你得到:

$sql_wallpaper = "SELECT * from wallpaper where height = 1600 order by RAND() limit 0,3"; 

我fyou要添加的寬度爲第二個參數,你可以做到這一點是這樣的:有或語句

$sql_wallpaper = "SELECT * from wallpaper where height = 1600 OR width = 1024 order by RAND() limit 0,3"; 

,或者你想與和語句來做到這一點:

$sql_wallpaper = "SELECT * from wallpaper where height = 1600 AND width = 1024 order by RAND() limit 0,3"; 

編輯: 如果你想選擇所有可用的壁紙,或有高度1600,1920或1280你可以使用類似的東西:

SELECT * FROM wallpaper WHERE height = 1600 OR height = 1920 OR height =1280 
+0

如何選擇多分辨率,如:height = 1600,1920,1280 等?? – Hassan 2011-04-10 22:05:00

+0

我已編輯上面的帖子... – 2011-04-10 22:51:49

2

您可以使用OR這裏得到具有一定寬度或高度的東西,例如

$sql_wallpaper = "SELECT * FROM wallpaper 
    WHERE height = '1600' OR width = '1024' ORDER BY RAND() LIMIT 0,3"; 
相關問題