我有一个像下面这样的mysql表.我想要计算浆果和草莓之间的行数,在我的情况下,这两个水果之间是两行.我怎样才能做到这一点?
id fruit
1 apple
2 berry
3 banana
4 pineapple
5 strawberryRun Code Online (Sandbox Code Playgroud)
我试图从mysql数据中调用foreach循环中的所有值,并将值输入用于另一个mysql select语句.看下面的代码.它只能收集一个值.我想使用第一个foreach循环包括整个部分,但是,因为foreach值是个体的,我需要爆炸数组为PDO准备.所以,最后,我想知道一种从外部foreach循环中获取所有值的方法.欣赏.
//mysql connection code, remove because it is not relative to this question
foreach ($tag_id as $term){
$term=$term['term'].' ';//use space to seprate each one
}
echo $term:// only can can one, how can I get all result from above foreach.
$term=explode(' ', $term);
$stm =$db->prepare("SELECT user_id FROM sign WHERE term IN (:term_0,:term_1,:ts.id, s.term, s.counter, os.user_id, os.id, COUNT(oserm_2,:term_3,:term_4,:term_5,:term_6,:term_7,:term_8,:term_9,:term_10)");
$term_0="$term[0]";
$term_1="$term[1]";
$term_2="$term[2]";
$term_3="$term[3]";
$term_4="$term[4]";
//following code is not relevive to this question.Run Code Online (Sandbox Code Playgroud)
我有一个问题,为此评级代码做悬停的事情.如果它转到第二个圆圈,前两个将突出显示,转到第三个,前三个将突出显示.我知道我应该使用+〜>,但我真的不明白如何使用这些来实现我想要的.欣赏.单击并查看代码.
#rating_bar{
width:100px;
height:100px;
margin: 4px 175px !important;
display:inline-block;
display:inline;
}
#rating_bar > span:before{
content:'O';
color: #c7c5c5;
cursor:pointer;
font-size:3em;
}
#rating_bar > span:hover:before {
color: #4bce32;
}Run Code Online (Sandbox Code Playgroud)
<div id="rating_bar">
<span id="rate_1"></span>
<span id="rate_2"></span>
<span id="rate_3"></span>
<span id="rate_4"></span>
<span id="rate_5"></span>
</div>Run Code Online (Sandbox Code Playgroud)
我的示例表如下.我有4个苹果,第一个苹果和第二个苹果之间有两排,第二个苹果和第三个苹果之间有一排,第三个苹果和第四个苹果之间有两排.是否可以通过Mysql了解每个苹果与下一个苹果之间的行数.
id fruit
1 berry
2 apple
3 bananan
4 berry
5 apple
6 berry
7 apple
8 berry
9 berry
10 apple
Run Code Online (Sandbox Code Playgroud) 看看我的代码,如果我使用echo $ html_of_questions,它可以工作.如果我使用return,则不起作用.为什么?我应该使用echo吗?因为有人告诉我应该总是在函数内部使用return.
<?php
function fruit($fruit){
$questions = [
'q1' => '<div>Is it good?</div>
<input type="text" value="submit"/>',
'q2' => '<div>where is it from?</div>
<input type="text" value="submit"/>',
];
$fruit_questions = [
'apple' => [1,3,5],
'banana' => [1,2,4],
'guava' => [17,21,4],
];
$question_keys = $fruit_questions[$fruit];
$html_of_questions = ''; // This will hold the questions to echo
foreach($question_keys as $question_key){
$html_of_questions .= $questions['q'.$question_key]
}
return $html_of_questions;//doesn't work, use echo it works
}
fruit('apple');
?>
Run Code Online (Sandbox Code Playgroud) 我想删除<a>包裹在<img>标签周围的标签.没有链接,只有图像显示,没有<a>html标签.但是,没有删除<a>直接在PHP中
我尝试使用css a{display:none;},但这会删除所有内容.您认为可以在PHP中执行我的要求吗?
请参阅下面的代码.
<a href=""> <img src="" /> </a>Run Code Online (Sandbox Code Playgroud)