开发者

Select from resolution width or height

开发者 https://www.devze.com 2023-02-23 04:00 出处:网络
I need to select a wallpaper from resolution of width or height from a table called wallpaper. How can I do this? I have:

I need to select a wallpaper from resolution of width or height from a table called wallpaper. How can I do this? I have:

$sql_wallpaper = "SELECT * from wallpaper 
                  WHERE height = '1600' ORDE开发者_运维问答R BY RAND() LIMIT 0,3";


You can use OR here to get something with a certain width or height, for example

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


If the type of your height and width field is numeric, so i would save the width and height as INT (range: -2.147.483.648 - 2.147.483.647, should be enough), because it is not usually that resolutions have got any decimals, then try to take the '1600' not as string (as you do, because here the 1600 is set in single quotianion marks) but as number and delete the quotation marks.

So you get:

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

I fyou want to add the width as second parameter, you can do this like this:

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

with an or-statement, or maybe you want to do it with an and-statement:

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

EDIT: IF you want to select all wallpapers that are available, or have the height 1600, 1920 or 1280 you could use something like that:

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

精彩评论

暂无评论...
验证码 换一张
取 消