我在postgresql上遇到了第一次痛苦的经历,当下的分钟挑战是:
如何在postgresql中执行concat_ws,通过以下方式从组中连接多个字段值:
select concat_ws(';',field_lambda) from table_lambda group by id;
Run Code Online (Sandbox Code Playgroud) 我有两个模型Businesses和Ratings.企业可以多次评级,每个评级存储0到5的整数.
我想创建一个"名人堂"页面,在那里我列出前十大企业,通过基于平均评级(将使用该Ratings模型)对业务进行分类,并将结果限制为10.
我不确定如何为控制器编写hall_of_fame方法,还是我还需要一个帮助器呢?
我想在表单中添加一个简单的复选框:
$element = new Zend_Form_Element_Checkbox('dont');
$element->setDescription('Check this box if you don\'t want to do this action.');
$form->addElement($element);
Run Code Online (Sandbox Code Playgroud)
但是,这就是html的样子:
<dt id="dont-label"> </dt>
<dd id="dont-element">
<input type="hidden" name="dontAttach" value="0">
<input type="checkbox" name="dontAttach" id="dontAttach" value="1">
<p class="description">Don't attach a bulletin. I only want to send an email.</p>
</dd>
Run Code Online (Sandbox Code Playgroud)
这个问题是我使用jQuery来隐藏DT 内部标签和DD内部隐藏元素的所有DT/DD (因此我的html将验证并且隐藏的元素不会占用空间这页纸).有没有办法使用a Zend_Form_Element_Checkbox而不必显示隐藏的输入元素?我宁愿不搞乱我的jQuery代码添加更多警告,但如果必须的话,我会.
显然,我不能/不应该在checkbox元素之前删除隐藏元素.所以这是我的jQuery代码隐藏所有隐藏的表单元素在页面上显示:
//fix zf hidden element from displaying
$('input[type=hidden]').filter(function() {
var noLabel = $(this).closest('dd').prev('dt').html() === ' ';
var onlyChild = $(this).is(':only-child');
if (noLabel && onlyChild) {
return true;
}
return false; …Run Code Online (Sandbox Code Playgroud) 显然,代码中的绝大多数错误都是空引用异常.是否有任何一般技术可以避免遇到空引用错误?
除非我弄错了,否则我知道在F#这样的语言中,不可能有空值.但这不是问题,我问如何避免C#等语言中的空引用错误.
我有一个包含数组对象的数组.一组数组.当我将描述方法应用于数组时,我看不到内部数组中的数据.这是代码:
[runScoreDataArray addObject:[NSString stringWithString:currentUser]];
[runScoreDataArray addObject:[NSNumber numberWithDouble:mainScores.scoreTotal]];
NSLog(@"Array1 contains: %@", [runScoreDataArray description]);
// Now add the array runScoreDataArray to the Array highScoresArray
[highScoresArray addObject: runScoreDataArray];
// Empty the runScoresData Array after each run.
[runScoreDataArray removeAllObjects];
NSLog(@"Array2 contains: %@", [highScoresArray description]);
Run Code Online (Sandbox Code Playgroud)
runScoresDataArray的NSLog打印输出应该按原样读取:Array1包含:(USER1,34500)
NSLog for highScoresArray读取:ARRAY2包含:((),(),())
我希望在NSLog打印输出中看到每个数组元素的数据,而不是空括号.
问题:如何使用描述方法打印出数组数组的内容?
我正在尝试object.get_absolute_url()在保存表单后将用户重定向到新创建的对象.我没有使用通用视图,因此我无法使用该post_save_redirect参数.相关部分view是这样的:
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('story_detail', args=(story.user, story.id)))
Run Code Online (Sandbox Code Playgroud)
现在我如何获得和story之间的对象以便我可以进行查找?form.save()HttpResponseRedirectreverse
我相信我一直在编写一些效率低下的代码,但似乎无法找到一种更有效的编写方式.
这通常发生在json输出中,尽管我也遇到了一些html或xml输出的问题.
我在我的数据库中运行一个查询,它返回一个数组.说一个人最喜欢的食物.php的mysql_fetch_assoc返回
Array([person]=>john [food]=>chocolate) Array([person]=>john [food]=>pizza) Array([person]=>john [food]=>coffee) Array([person]=>susan [food]=>licorice)
为了创建我的json或html,我一直在寻找独特的人,然后添加这样的食物
$jsonOut=''
$personAdd='';
while($gotArray=mysql_fetch_assoc(foodArray)){
if($personAdd!='$gotArray['person']){
$jsonOut.="person: $gotArray['person'], foods{";
}
$jsonOut.="food:$gotArray['food'],";
rtrim(jsonOut,',');
$jsonOut.="}";
$personAdd=$array['person'];
}
现在,当你只有一个值在mysql响应中不断重复时,这不是什么大问题,但当你开始有4或5列的值相同时,它开始变得非常冗长.
有一个更好的方法吗?
-------------澄清输出应该是什么样的-----------------上面数组的最终json应该是这样的
[
{
"person": "john",
"foods": [
{
"food": "chocolate",
"food": "pizza",
"food": "coffee"
}
]
},
{
"person": "susan",
"food": "licorice"
}
]
或苏珊会有"食物":[{"food":"licorice"}]类似的东西.
编译时我收到以下错误消息,但我确定我在外部Project2.c文件中声明了变量.有人能给我一个提示我做错了吗?谢谢
1>main.obj : error LNK2001: unresolved external symbol _num_days
1>main.obj : error LNK2019: unresolved external symbol _countDays referenced in function _testIt
1>main.obj : error LNK2001: unresolved external symbol _what_birthday
1>main.obj : error LNK2001: unresolved external symbol _birth_day
1>main.obj : error LNK2001: unresolved external symbol _birth_month
1>main.obj : error LNK2001: unresolved external symbol _birth_year
Run Code Online (Sandbox Code Playgroud)
源代码:
#include <stdio.h>
/* the following five variables are defined inside project2.c */
extern int birth_year;
extern int birth_month;
extern int birth_day;
extern int what_birthday;
extern int …Run Code Online (Sandbox Code Playgroud)