我有这个数据表设置:
$(document).ready(function() {
$('#RectifiedCount').dataTable( {
"bJQueryUI": true,
"bProcessing": true,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bStateSave": true,
"sDom": '<"H"if>tr<"F"lTp>',
"aoColumns":[
{'sname':'count_id', 'sType':'numeric', 'bVisible':false},
{'sName':'count_type', 'sType':'string','bVisible':true},
{'sName':'count_date', 'sType':'date','bVisible':true},
{'sName':'count_count', 'sType':'numeric','bVisible':true},
{'sName':'count_notes', 'sType':'string','bVisible':true}
],
"oTableTools": {
"sRowSelect": "single",
"sSwfPath": "media/swf/copy_cvs_xls_pdf.swf",
"aButtons": [ {sExtends :'select_none' , 'sButtonText':'Clear Selection'}],
"fnRowSelected": function(node){
var s=$(node).children();
if($(s[0]).text()=='Delivery') return ;
$('select[name="count_type"]').val($(s[0]).text());
$('input[name="count_date"]').val($(s[1]).text());
$('input[name="count_count"]').val($(s[2]).text());
$('textarea[name="count_notes"]').val($(s[3]).text());
}
},
'sScrollX':'100%'
});
});
Run Code Online (Sandbox Code Playgroud)
当我选择一行时,我想将该行单元格的值复制到一些名称与'sName'属性相同的表单字段中.我有两个问题:
node['sName_whatever'].value
这样的东西会很好.(遗漏了不重要的东西)
$(document).ready(function() {
rctable=$('#RectifiedCount').dataTable( {
"aoColumns":[
{'sname':'count_id', 'sType':'numeric', …
Run Code Online (Sandbox Code Playgroud) 我正在清理R中的文本字符串.我想删除除撇号和连字符之外的所有标点符号.这意味着我不能使用[:punct:]
角色类(除非有一种说法[:punct:] but not '-
).
! " # $ % & ( ) * + , . / : ; < = > ? @ [ \ ] ^ _ { | } ~.
和反击必须出来.
对于上述大部分内容,转义不是问题.但对于方括号,我确实遇到了问题.这是我尝试过的:
gsub('[abc]', 'L', 'abcdef') #expected behaviour, shown as sanity check
# [1] "LLLdef"
gsub('[[]]', 'B', 'it[]') #only 1 substitution, ie [] treated as a single character
# [1] "itB"
gsub('[\[\]]', 'B', 'it[]') #single escape, errors as expected
Run Code Online (Sandbox Code Playgroud)
错误:'['是字符串中无法识别的转义"'[[" …
我有一个用ggplot2制作的堆叠areaplot:
dists.med.areaplot<-qplot(starttime,value,fill=dists,facets=~groupname,
geom='area',data=MDist.median, stat='identity') +
labs(y='median distances', x='time(s)', fill='Distance Types')+
opts(title=subt) +
scale_fill_brewer(type='seq') +
facet_wrap(~groupname, ncol=2) + grect #grect adds the grey/white vertical bars
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
我想在控制图的配置文件(右下角)中添加一个叠加到输出中的所有图形(groupname == rowH是控件).
到目前为止,我的最大努力已经产生了这个:
cline<-geom_line(aes(x=starttime,y=value),
data=subset(dists.med,groupname=='rowH'),colour='red')
dists.med.areaplot + cline
Run Code Online (Sandbox Code Playgroud)
我需要3条红线作为1条红线,掠过深蓝色部分的顶部.我需要相同的线(rowH线)来覆盖每个面板.
数据框如下所示:
> str(MDist.median)
'data.frame': 2880 obs. of 6 variables:
$ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
$ fCycle : Factor w/ 6 levels "predark","Cycle 1",..: 1 1 1 1 1 1 1 1 1 …
Run Code Online (Sandbox Code Playgroud) 我有一个data.frame(链接到文件),有18列和11520行,我这样转换:
library(plyr)
df.median<-ddply(data, .(groupname,starttime,fPhase,fCycle),
numcolwise(median), na.rm=TRUE)
Run Code Online (Sandbox Code Playgroud)
根据system.time(),运行需要很长时间:
user system elapsed
5.16 0.00 5.17
Run Code Online (Sandbox Code Playgroud)
此调用是webapp的一部分,因此运行时非常重要.有没有办法加快这个调用?
编辑:现在下面的函数正确地做了缩写,实现了@Asad的解决方案
嗨,我目前正在开发一个类似的按钮,我已经完成了所有的基本功能,但是我已经启动了数字缩写代码并打了一堵墙,因为我无法弄清楚如何使缩写更精确.
我有一个数字,例如1000,1230,1500,154000,1500000,1000000
我想用缩写格式化它们.即
如果它是一千,那么1k,1.1k,2k,10k,10.5k等......
对于数十,数十万和数百万等等......
目前我有以下功能,但它不够具体:
function abreviateTotalCount($value)
{
$abbreviations = array(12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => '');
foreach($abbreviations as $exponent => $abbreviation)
{
if($value >= pow(10, $exponent))
{
return round(floatval($value / pow(10, $exponent))).$abbreviation;
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
比方说,我们有直接绑定到数据库表的3个主要角色user
:ROLE_USER
,ROLE_MODERATOR
和ROLE_ADMIN
.
但是,我们还有一些其他角色,用于Crews
组件(参见下面的UML).我用的peformed行动以下角色Crew
:ROLE_CREW_BOSS
,ROLE_CREW_LEFTHAND
,ROLE_CREW_RIGHTHAND
,ROLE_CREW_MEMBER
.
+----------------+ +------------------+ | users | | crews | |----------------| |------------------| | id | | id | | username <---+ | name | | password | | +---> cash | | roles | | +-------------------+ | | ... | | ... | | | crew_members | | | | | | | |-------------------| | | | +----------------+ | | …
DatePeriod是一个用于处理重复日期的PHP类.它的方法数量非常有限.因此,当我想要使用重复日期执行基本数组函数时,我必须将其复制到数组中iterator_to_array
.奇怪的是,复制它似乎破坏了它.有什么想法吗?
$p=new DatePeriod(date_create('2008-01-01'),
DateInterval::createFromDateString( "+2 days" ),
date_create('2008-12-31'));
echo count(iterator_to_array($p)); //183
$a=iterator_to_array($p);
echo count($a); //0
Run Code Online (Sandbox Code Playgroud) 我使用以下代码成功查询用户的Active Directory:
$filter = (&(objectCategory=person)(samaccountname=someusername));
$fields = array("samaccountname","mail","manager","department","displayname","objectGUID");
$user = ldap_search($ldapconnection, $baseDn, $filter, $fields);
Run Code Online (Sandbox Code Playgroud)
结果数组为manager
属性提供此值:
CN=McBossy\, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com
Run Code Online (Sandbox Code Playgroud)
这看起来像是一个尊贵的名字给我.但是当我试图查询经理的记录时,
$filter = (&(objectCategory=person)(dn='CN=McBossy\, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com'));
$manager = ldap_search($ldapconnection, $baseDn, $filter, $fields);
Run Code Online (Sandbox Code Playgroud)
查询失败 PHP Warning: ldap_search(): Search: Bad search filter
我尝试了很多种可能性,包括不同的引用,更多的括号,使用distinguishedName
而不是dn
等等.
我做错了什么,以及获得经理记录的正确方法是什么?
我有一组表单验证规则,我用jquery 验证器插件编写.由于我必须在服务器端重复相同的验证,我认为不必在PHP中重写我的规则会很好.如果规则很简单,field=>rulename=>value
我可以将它们存储为JSON并将它们解码为PHP数组.不幸的是,一些规则依赖于其他字段或具有计算值.
有没有field=>rulename=>value=function{}
从javascript/jquery转换为PHP 的通用方法?或者,有没有办法在服务器端运行jquery,然后将结果传递给PHP?
一些规则的示例:
rules: {
title: {required:true, minlength:5},
description: {required:true, minlength:5},
event_type_id: "required",
ev_start: { dateCan: true, required: true},
ev_end:{ dateCan: true,
minDate: "input[name='ev_start']"
},
ev_starttime:{
required:
function(element){
return $("input[name='allday']:unchecked")
},
time: true,
maxTime: {
depends: function(element) {
return $("input[name='ev_endtime']:filled")
&& $("input[name='ev_start']").valid()
&& $("input[name='ev_end']").valid()
&& $("input[name='ev_start']").val()==$("input[name='ev_end']").val()
},
param: "input[name='ev_endtime']"
}
},
//etc...
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个显示数据库表中项目的系统,具体取决于它们是否可用.
我有两张桌子:
预订电话:
----------------------------------------------------------------------
| ResID | CarID | UserID | startTime | startDate | endTime | endDate |
----------------------------------------------------------------------
| 1 | 4 | 4 | 13:00:00 |2013-04-21 |13:00:00 |2013-04-29|
Run Code Online (Sandbox Code Playgroud)
和汽车:
-------------------------------------------
| CarID | make | model | serial | image |
-------------------------------------------
| 1 | Honda | civic | ky675 | 1.png |
Run Code Online (Sandbox Code Playgroud)
因此,当用户访问页面时,他们输入开始日期和结束日期,然后在运行查询后显示汽车列表以检查汽车是否在该日期可用.
所以我提出了这个问题.
$carstring = mysql_query("SELECT * FROM cars
{$statement}
AND deleted = 'no'
AND carID NOT IN (
SELECT carID FROM reservations
WHERE startDate …
Run Code Online (Sandbox Code Playgroud)