我有一个数组有多个对象(比如3个对象),每个对象有3个"键 - 值"对.
$PredefinedResult 是这样的:
[
{
"EffectiveStatusId":0,
"EffectiveStatus":"abc",
"RecordCount":0
},
{
"EffectiveStatusId":0,
"EffectiveStatus":"def",
"RecordCount":0
},
{
"EffectiveStatusId":0,
"EffectiveStatus":"ghi",
"RecordCount":0
}
]
Run Code Online (Sandbox Code Playgroud)
我有另一个对象数组,其名称为$MainResult:
[
{
"EffectiveStatusId":1,
"EffectiveStatus":"abc",
"RecordCount":7
},
{
"EffectiveStatusId":6,
"EffectiveStatus":"def",
"RecordCount":91
}
]
Run Code Online (Sandbox Code Playgroud)
预期结果 :
我想用对象替换里面的类似$PredefinedResult对象,$MainResult并希望得到如下结果:
[
{
"EffectiveStatusId":1,
"EffectiveStatus":"abc",
"RecordCount":7
},
{
"EffectiveStatusId":6,
"EffectiveStatus":"def",
"RecordCount":91
},
{
"EffectiveStatusId":0,
"EffectiveStatus":"ghi",
"RecordCount":0
}
]
Run Code Online (Sandbox Code Playgroud)
我尝试了什么:
我试过这个代码,但它没有给我想要的结果.
$FinalResult = array_replace($PredefineResult,$MainResult);
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何获得上面提到的预期结果?
$q = $this->db->select('
books.title,
reserved_books.id,
reserved_books.isbn,
reserved_books.price,
reserved_books.item_sold,
reserved_books.date_sold,
reserved_books.total_amount
')
->from('reserved_books')
->join('books','reserved_books.isbn= books.isbn')
->limit($limit,$offset);
Run Code Online (Sandbox Code Playgroud)
我怎么能在我的查询中使用distinct?reserved_books.isbn是唯一的.
我正在尝试学习Codeigniter并了解到目前为止的基础知识,但是当我尝试测试时,似乎缓存正在阻碍.通常,当我在localhost上测试时,我做了一个更改并立即在浏览器中看到它,但是使用Codeigniter,似乎我需要等待~1分钟才能在浏览器中看到更改.有没有办法普遍禁用Codeigniter缓存,以便在发生变化时立即发生?
伙计们.我正在使用codeigniter.我使用.htaccess从我的url中删除'index.php',并将"Allow from all"添加到我的default.conf中.'index.php'已成功删除,网站正在运行.但是自上次更新apache以来,.htacess停止了工作,并且在URL中需要'index.php'.这是我新更新的000-default.conf.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless. …Run Code Online (Sandbox Code Playgroud) 我遵循数据库架构 -

现在部门,年份和部门表已经填满了信息.
我现在需要插入学生数据.学生数据将从xls文件导入(导入和解析部分已完成).正如您在架构中看到的那样,表中的列student_data引用year_id,department_di和division_id.因此,在插入时我需要他们的ID字段,因为xls具有各自的名称值.
所以我要根据每个学生的列值来获取相应的ID.因此,这引入了3个查询,用于在学生表中插入一条记录.像这样 -
forloop(...):
$studentData = new Entities\StudentData();
$year = $this->em->getRepository("Entities\Year")->findBy(array('year_name' => $this->year[$i]));
$department = $this->em->getRepository("Entities\Department")->findBy(array('department_name' => $this->branch[$i]));
$division = $this->em->getRepository("Entities\Division")->findBy(array('division_name'=>$this->division[$i]));
$studentData->setYear($year[0]);
$studentData->setDepartment($department[0]);
$studentData->setDivision($division[0]);
//other data
.
.
.
.
.
$this->em->persist($studentData);
endforloop();
$this->em->flush();
$this->em->clear();
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我将为每个部门,年份和部门获得ID循环.假设我正在导入100个学生列表,因此它最终会运行300个查询来获取这3个ID字段.
我可以在插入数据时直接从他们的名字中获取年份,部门和部门的ID吗?我是学说的新手,我不知道如何去做.
更新 如果问题不清楚,请告诉我.我可以用更多细节更新它或重组它.
我正在制作一个网页,这是一个单页网站,通过CodeIgniter中的Ajax与服务器进行交互.一般编码具有以下类型:
controller (user.php):
public function get_user_content() {
$id = $this->input->post('id');
$hits = $this->user_model->user_data($id);
$s = '';
foreach ($hits as $hit) {
$s .= $hit->name;
$s .= $hit->age;
}
echo $s;
}
Run Code Online (Sandbox Code Playgroud)
model(user_model.php):
function user_data($id) {
//do sql operation
return $query->result();
}
Run Code Online (Sandbox Code Playgroud)
视图:
...
...
<a href="#" id="23" class="user-data">Click here for user details</a>
...
...
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
('.user-data').click(get_user_data);
....
....
function get_user_data(response) {
return $.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/user/get_user_content",
data: { id: this.id },
success: function(response) {
$("#somediv").append(response); …Run Code Online (Sandbox Code Playgroud) 我正在使用codeigniter会话来存储用户登录.当用户在多个选项卡中打开时,在一个选项卡中注销时,我希望在用户访问其他选项卡时自动刷新页面.这可能吗?
使用带有我的codeigniter应用程序的SMTP时,我无法收到要发送的电子邮件.
在SO上有很多类似的问题,但没有一个可以解决我的问题,所以这就是为什么我要再问一次.
这是我得到的错误:
hello:
The following SMTP error was encountered:
Failed to send AUTH LOGIN command. Error:
from:
The following SMTP error was encountered:
to:
The following SMTP error was encountered:
data:
The following SMTP error was encountered:
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Tue, 22 Apr 2014 22:54:12 -0400
From:
Return-Path:
To: myemail@gmail.com
Subject: =?utf-8?Q?Request_from_C&J_Builders_Contact_form?=
Reply-To: "donotreply@C&JBuilders.us" …Run Code Online (Sandbox Code Playgroud)