我有一个包含字符串的表列。此字符串的长度取决于存储在其中的变量数量,但始终遵循相同的模式。该字符串是由Wordpress插件动态生成的,我对它的存储方式没有任何影响。这是:
a:3:{i:0;s:3:"509";i:1;s:3:"511";i:2;s:3:"514";}
用户可以从HTML表单中的多个选择字段中选择任意数量的变量。我将这些存储在会话中:
Array ( [0] => 511 [1] => 514 )
会话必须至少包含一个值,但可以包含更多值。
如何在表格列中搜索511或514等(存储在我的会话数组中)的出现?
我到目前为止尝试了LIKE,IN和EXISTS,但没有一个正在工作。
请注意我使用的是WP_query(Wordpress),因此我可以使用的唯一操作符是:
'=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' and 'NOT EXISTS'
以防任何人需要它,这里是我使用的WP_query元数据查询数组:
array(
'key' => 'teacher',
'value' => $_SESSION['selected_teachers'],
'compare' => 'IN'
)
非常感谢提前!
答案 0 :(得分:1)
尝试生成WP_query的meta_query
<View style={styles.container}>
<View style = {styles.backgroundContainer}>
<Image source = {require('./img/landing-background.jpg')} resizeMode = 'cover' style = {styles.backdrop} />
</View>
<View style = {styles.overlay}>
<Text style = {styles.headline}>It should appear in front of the Background Image</Text>
<Image style = {styles.logo} source = {require('./img/logo.png')} />
</View>
</View>
var styles = StyleSheet.create({
backgroundContainer: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
container: {
flex: 1,
alignItems: 'center',
},
overlay: {
opacity: 0.5,
backgroundColor: '#000000'
},
logo: {
backgroundColor: 'rgba(0,0,0,0)',
width: 160,
height: 52
},
backdrop: {
flex:1,
flexDirection: 'column'
},
headline: {
fontSize: 18,
textAlign: 'center',
backgroundColor: 'black',
color: 'white'
}
});
这将使用&#39; WHERE ... LIKE%...%&#39;生成mysql查询,它会有一些性能问题。
答案 1 :(得分:0)
我认为您可以在此处找到问题的答案:https://wordpress.stackexchange.com/questions/18703/wp-query-with-post-title-like-something
[抱歉写了一个答案,但我还不能发表评论]