如何在Codeigniter中运行删除查询。我有一组数组和一个键。在MySQL中,我的查询运行完美。
DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)
Run Code Online (Sandbox Code Playgroud)
在Codeigniter中,如何编写和运行此查询。我尝试了下面的代码,但无法正常工作。
$ids = '5,9,12';
$this->db->where('style_id', $style_id)->where_not_in('ID', $ids);
$this->db->delete('TABLE');
Run Code Online (Sandbox Code Playgroud) 我正在使用codeigniter MVC,我想允许用户删除他们的页面.
因此,如果page_id = 1要传递以user_id =1进行删除,则只应删除表中user_id = 1和page_id = 1的行.
这是我的model_page.php代码到目前为止,但user_id 1的所有页面都在删除
function delete_user_page($user_id, $page_id){
$query = $this->db->where('user_id', $user_id and 'page_id', $page_id);
return $this->db->delete('mysql_table');
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我有这个我要重定向到的URI:redirect('search_results/result/$id');
我收到此错误:The URI you submitted has disallowed characters.
你知道我怎么能解决这个问题吗?
我正在尝试使用codeigniter上传图像。但是,当我选择并上传文件时,它不会移动到我的目标文件夹中。
这是我的控制器代码。
if(empty($_FILES['pwd']['name']))
{
$error=array(
'error_img'=>'Image file empty !!!.'
);
$this->index();
}
else
{
$type=explode('.',$_FILES["pwd"]["name"]);
$type=$type[count($type)-1];
$url="./photos/".uniqid(rand()).'.'.$type;
if(in_array($type,array("jpg","jpeg","gif","png")))
if(is_uploaded_file($_FILES["pwd"]["tmp_name"]))
if(move_uploaded_file($_FILES["pwd"]["tmp_name"],$url))
return $url;
return "";
}
Run Code Online (Sandbox Code Playgroud) 我在codeigniter中开发应用程序,在发送邮件白色注册时收到以下错误.
PHP不推荐使用:与其类同名的方法将不会是PHP的未来版本中的构造函数; emailcomm在第3行的/var/www/html/portal/application/libraries/emailcomm.php中有一个弃用的构造函数
我的库文件位于emailcomm.php下面
class emailcomm
{
var $to;
var $subject;
var $message;
var $from='From:';
function emailcomm()
{
$this->CI=&get_instance();
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = '465';
$config['_smtp_auth']=TRUE;
$config['smtp_user'] = 'contact-us@webtech.com';
$config['smtp_pass'] = 'Web8*98*2015';
$config['smtp_timeout'] = '60';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = "html";
$this->CI->load->library('email',$config);
$this->CI->email->initialize($config);
}
}
Run Code Online (Sandbox Code Playgroud)
最近升级服务器到php7.在升级它工作之前,现在它不工作.现在我正在检查上面显示错误的错误日志.我可以在这个代码中更改?谁能帮帮我吗 .谢谢
最近,在我基于CodeIgniter的一个项目中,我需要从Excel文件(.xlsx和.xls)读取数据,并将这些数据插入MySQL。不幸的是,我以前没有使用过PHPSpreadsheet(因为我不需要使用Excel :()。
到目前为止,我所做的是,从Github 下载PHPSpreadsheet并将其解压缩到我的CodeIgniter项目的根目录中。
CodeIgniter根目录中的PHPSpreadsheet。
到目前为止,我已经尝试将官方文档示例导入到我的CI应用程序中:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpSpreadsheet\IOFactory;
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$inputFileType = 'Xlsx';
$inputFileName = 'test.xlsx';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
print_r( $spreadsheet );
}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何在CodeIgniter中使用PHPSpreadsheet从Excel文件中读取数据并将其存储到MySQL数据库中?
我在我的模型中使用以下函数:
function uploadsinglepicture($uploadpath){
$config['upload_path'] =$uploadpath;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '';
$config['max_width'] = '';
$config['max_height'] = '';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
if($this->input->post('id') == ''){
$insertion['image'] = '';
}
//$this->load->view('upload_form', $error);
}
else{
$data = array('upload_data' => $this->upload->data());
$insertion['image'] = $data['upload_data']['file_name'];
}
$image = $insertion['image'];
return $image;
}
Run Code Online (Sandbox Code Playgroud)
这是我访问控制器中的函数的方法:
if(!empty($this->input->post())){
$path= base_url().'assets/front/img';
$this->general->uploadsinglepicture($path);
redirect(base_url().'admin/home/index/sliderupated');
}
Run Code Online (Sandbox Code Playgroud)
但我得到的错误是:
数组([错误] =>上传路径似乎无效.)
如果我打印$path,这就是我得到的
http://localhost/site/assets/front/img/
Run Code Online (Sandbox Code Playgroud)
并在浏览器中以真实路径打开.我在视图中的代码如下
<form method="post" enctype="multipart/form-data" action ="<?=base_url()?>admin/home/index" >
<label>Upload Picture </label> …Run Code Online (Sandbox Code Playgroud) 我想用这样的codeigniter构建一个查询.
SELECT*FROM
tableWHERE machine = $ var AND date BETWEEN' $ today'和'$ oneMonthAgo'
我的模态
public function getHistory($machine)
{
$today = date('Y-m-d');
$month=date('Y-m-d',strtotime("-1 month"));
$query = $this->db->from('table')->where('machine', $machine)->where("date BETWEEN '$today' AND '$month'")->get();
if ($query->num_rows() > 0) {
return $query->row();
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在尝试,但我没有得到结果加:用这行可以计算一个月前的日期
$today = date('Y-m-d');
$month=date('Y-m-d',strtotime("-1 month"));
Run Code Online (Sandbox Code Playgroud)
对不起我的英文xP
php echo以"@"符号开头显示变量,
例:
<?php echo @$user_profile['id'];?>
Run Code Online (Sandbox Code Playgroud)
为什么在这里使用@符号?
我有多个日期,我需要计算数据库中特定日期的记录数.我正在使用下面的代码,但是..问题是它会在循环内每次都有借口.我相信有更好的方法可以做到这一点.提前致谢.
for ($i = 0; $i <= $total_difference; $i++){
$date = strtotime("+$i day", strtotime($start_date));
$check_date = date("Y-m-d", $date);
// Here i have to check the record against $check_date
$query = $this->db->select("SELECT COUNT(task_date) as COUNT FROM
time_management");
$this->db->from('time_management');
$this->db->where('task_date',$check_date);
$result = $this->db->get()->row_array();
$count = $result['COUNT'];
echo "count for $check_date is $count";
}
Run Code Online (Sandbox Code Playgroud)