我有一个分页的文章列表需要按排名排序,但当文章的位置<> 0时,它必须插入该特定位置.我认为我至少可以为当前页面提取正确位置的文章,然后在PHP中对它们进行排序,以便在适当的位置显示.我想在MySQL中只用一个查询来做这个
我的一些尝试是:
此查询首先尝试选择具有当前页面正确位置的文章,然后选择排名最高的文章
SELECT id, rank_score, position
FROM Articles
ORDER BY ((position <= (50 * 1)) AND (position > 50 * (1-1))) DESC, rank_score DESC
LIMIT 0, 50
Run Code Online (Sandbox Code Playgroud)
50是页面上显示的文章数,1是当前页码,它们是在查询生成时添加的.
此查询的问题在于,第2页上的结果是错误的,因为通过添加LIMIT 50,50,您可以超越在该页面上具有位置的文章.
另一种尝试:
SELECT (
SELECT id, rank_score, position
FROM Articles
ORDER BY ((position <= (50 * 1)) AND (position > 50 * (1-1))) DESC, rank_score DESC
LIMIT 50)
UNION (
SELECT id, rank_score, position
FROM Articles
ORDER BY rank_score DESC LIMIT x)
Run Code Online (Sandbox Code Playgroud)
要正常工作,第二个查询的限制必须等于第一个查询返回的行数.此外,任何时候一个具有非常高的排名,但也是非常高的位置的文章,它将在前面显示,因为在第二个查询中忽略了位置.
我想对除jquery中的IE之外的所有其他浏览器执行绝对位置.我有以下代码.
<script type="text/javascript">
var positions=$("#gift_field").position();
var top=positions.top;
$("#discount_box").css("float","right");
if (!$.browser.msie){
$("#discount_box").css("position","absolute");
}
$(".discount_box").css("top",positions.top);
var wd=(positions.left) + 400;
$(".discount_box").css("left",wd);
</script>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
请考虑以下带有样式的HTML.
<div style="border: 1px solid;height: 600px;">
<button id="create_new_estimate" style="position:relative;top:10px;left:10px;">
Create New Estimate
</button>
<table style="position:relative;top:10px;left:300px;">
<tr>
<td>
cell 1
</td>
</tr>
<tr>
<td>
cell 2
</td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到它.
我希望能够将这两个元素并排放置.最终我将在这个div中添加更多元素.我认为这样position:relative我就可以给每个元素赋一个topand leftstyle属性,使它相对于父div有一个位置.但是正如你在这个例子中看到的那样,两个元素都有,top:10px;所以我希望它们彼此相邻,但它们并不是彼此相邻的.
你知道我可以使用什么样式,所以我可以简单地给每个元素一个top和left属性来将它们放在父元素中.谢谢!
我想在应用程序启动时将一些图像放在一个区域中.由于图像数量不是固定数量,因此我必须动态创建图像.我想设置每个图像的位置/边距,同时创建它们以获得良好的平衡.
我试过以下,但没有效果.·创建后,使用imageview.layout().·使用LayoutParams.margins().·使用AsyncTask设置边距.·activity.runOnUiThread().
这是代码:
// After access server, if needed then add a imageview to the 'c_box'
// c_box: the parent that imageview to add.
FrameLayout c_box = (FrameLayout) findViewById(R.id.c_box);
MarginLayoutParams mlp = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageView img1 = new ImageView(this);
img1.setImageResource(R.drawable.c_file);
img1.setLayoutParams(params);
img1.setLongClickable(true);
img1.setId(img_id);
c_box.addView(img1);
img1.setOnTouchListener(listener);
**// it's possible to set the position by layout or margin?
img1.layout(100, 100, 200, 200);**
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里调用invalidate()方法.
// After access server, if needed then add a imageview to the 'c_box'
// c_box: the parent that …Run Code Online (Sandbox Code Playgroud) 我hover在一个元素上设置了一个事件,该元素使用jQuery UI的position函数div在其下方显示一个右侧,并将"out"设置为隐藏它div.
问题是,随后div在每次悬停时徘徊的位置越来越远.
示例:http://jsfiddle.net/Shpigford/8ZkgJ/
将鼠标悬停在红色框上,然后再次将鼠标悬停在它上方,您会看到蓝色框快速进一步定位到右侧.
如果我改变一个click事件,也会发生同样的事情.当我隐藏div并然后再次尝试显示它时,似乎有些奇怪的事情正在发生.

我想像上面的图片一样定位蓝色方块,蓝色视图的中心位于另一个视图的角落.怎么做?
我无法在屏幕底部重新定位我的admob横幅,无论我尝试过它都保持在顶部 ..我发现了很多这样的问题,我已经尝试了他们做了什么,没有任何效果.以下是我的尝试:
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView?.adUnitID = "ca-app-pub-466066799532826501/8972705271"
bannerView?.delegate = self
bannerView?.rootViewController = self
let screenRect = UIScreen.mainScreen().bounds
let screenWidth = screenRect.size.width
let screenHeight = screenRect.size.height
let screenXPos = (screenWidth / 2)
let screenYPos = screenHeight - kGADAdSizeBanner.size.height
bannerView!.frame = CGRectMake(screenWidth/2.0 - bannerView!.frame.size.width/2.0, screenHeight - bannerView!.frame.size.height,
bannerView!.frame.size.width,bannerView!.frame.size.height);
self.view.addSubview(bannerView!)
bannerView?.loadRequest(GADRequest())
timerAd?.invalidate()
timerAd = NSTimer.scheduledTimerWithTimeInterval(40, target: self, selector: "GoogleAdRequestTimer", userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud) 这是一个简单的CSS问题,但我还没有任何线索.我有几个带有背景颜色的p标签,我的问题是背景扩展到每个标签的屏幕的100%,我只是想包装单词,创建效果作为buttoms或block.我不明白为什么p背景会达到所有宽度.
小提琴:这里的确切示例
<div class="process_wrapper_mobile">
<div class="inter_mobile_process">
<p>Interview</p>
</div>
<div class="inter_mobile_process">
<p>Data reception</p>
</div>
<div class="inter_mobile_process">
<p>Design</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.process_wrapper_mobile {
position: relative;
float: left;
width: 100%;
height: auto;
background-color: #CCC;
}
.process_wrapper_mobile .inter_mobile_process {
position: relative;
float: left;
width: 100%;
height: auto;
margin-bottom: 3%;
}
.process_wrapper_mobile .inter_mobile_process p {
text-align: center;
color: #fff;
font-size: 0.9em;
background-color: #333;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
padding: 3% 5%;
}
Run Code Online (Sandbox Code Playgroud)
请检查我的小提琴.
谢谢!
当用户单击窗口的任何部分时,我试图获取单击的位置.我在许多教程中发现了这段代码,但似乎没有用.
(function( $ ) {
$( document ).ready(function() {
$( window ).click(function( e ) {
var offset = $(this).offset(),
relativeX = (e.pageX - offset.left),
relativeY = (e.pageY - offset.top);
alert("X: " + relativeX + " Y: " + relativeY);
});
});
})( jQuery );
Run Code Online (Sandbox Code Playgroud)
Firefox控制台告诉我"TypeError:offset is undefined",我不明白为什么它不起作用.
检索窗口上的点击位置的正确方法是什么?
在python中如何将字符串中的字符移动x个量?
例如,假设输入是"你好"
如何将字符串中的每个字符移动1,以便得到的输出是:"ohell"