从分辨率宽度或高度中选择

时间:2011-04-10 17:30:45

标签: php mysql

我需要从名为wallpaper的表中选择宽度或高度分辨率的壁纸。我怎样才能做到这一点?我有:

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

2 个答案:

答案 0 :(得分:2)

您可以在此处使用OR来获取具有特定宽度或高度的内容,例如

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

答案 1 :(得分: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";

我想将宽度添加为第二个参数,你可以这样做:

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

带有or-statement,或者你想用an语句:

$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