我试图使用csv插入记录.我想将csv上传到我的应用程序,并希望将其导入数据库.现在我有一个用户表,所以我想通过导入用户的csv文件来创建用户.我知道一些关于文件上传但是关于将其导入数据库的问题请帮忙.
请参阅我使用以下命令完成文件上传:控制器:
public function upload_csv()
{
$this->load->helper('form');
$this->load->helper('url');
//Set the message for the first time
$data = array('msg' => "Upload File");
$data['upload_data'] = '';
//load the view/upload.php with $data
$this->load->view('admin/user/upload', $data);
}
Run Code Online (Sandbox Code Playgroud)
另一个Controller Upload_file
public function upload_it() {
//load the helper
$this->load->helper('form');
//Configure
//set the path where the files uploaded will be copied. NOTE if using linux, set the folder to permission 777
$config['upload_path'] = 'application/views/uploads/';
// set the filter image types
$config['allowed_types'] = 'gif|csv';
//load the upload library
$this->load->library('upload', …Run Code Online (Sandbox Code Playgroud) 我的php有问题.我一直在使用codeigniter,以下代码返回给我这个错误消息:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: item
Filename: views/banner.php
Line Number: 37
Run Code Online (Sandbox Code Playgroud)
我的控制器如下:
public function __construct()
{
parent::__construct();
$this->auth->check();
$this->load->database();
$this->load->helper('url');
$this->load->model('banner_model');
}
public function index()
{
$dados['banner'] = $this->banner_model->recuperar_todos_banners();
$this->load_view("banner", $dados);
}
Run Code Online (Sandbox Code Playgroud)
我的看法:
<? foreach ($banner as $item):?>
<tr>
<td><?=$item->chave?></td>
<td><?=$item->imagem?></td>
<td><?=$item->descricao?></td>
<td><?=$item->link?></td>
<td>
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<? endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
我使用var_dump测试了两个变量.此代码的目的是访问MySQL数据库并将结果存储在数组中.$ banner变量工作正常,所有数据都在那里,因此每个位置都被对象占用,每个对象都是一个表行.
我知道之前在StackOverflow上已经问过这个问题,但我仍然无法弄清楚到底发生了什么.
创建查询时,我想要使用join两次,如下所示:
$this->db->select('*');
$this->db->from('members');
$this->db->join('members_group', 'members_group.mgid = members.mgid');
$this->db->join('members_profiles','members_profiles.mid = members.mid');
$this->db->where('members.mid=' . $id);
$this->db->get()
Run Code Online (Sandbox Code Playgroud)
join语句编号2中的问题,如果members_profiles表中没有数据,则查询返回空数组.但如果我删除join语句号2,结果将是正确的数据.
如何使 members_profiles 表包含与成员相关的数据,如何使查询返回数据?
实时获取以下错误
“遇到PHP错误
严重性:核心警告
消息:模块'ffmpeg'已加载
文件名:未知行号:0
回溯::”。
但是我没有在本地主机中收到此错误。我正在使用codeigniter3。需要一些帮助。
如何使用给定的语法在CodeIgniter中显示数据库表名列表:
$tables=$this->db->query("SHOW TABLES LIKE '%Demo%'");
Run Code Online (Sandbox Code Playgroud) 对不起我的无知,但codeigniter对我来说是新的.所以我不知道如何将值插入数据库.所以我的基本问题是我想了解如何将值从视图插入控制器到数据库中的模型.
这是我的控制器文件......
<?php
class Form extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required',
array('required' => 'You must provide a %s.')
);
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
}
}?>
Run Code Online (Sandbox Code Playgroud)
这是我的视图文件.
<?php
//print_r($data);
echo form_open();
?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是模型文件.. …
我试图在代码输入if语句时显示一个字符串.
我仔细检查过,代码确实进入了声明,但没有打印出来.
这是我的控制器功能:
public function clock_in()
{
$this->load->model('model_users');
$this->db->where('USER_EMAIL', $this->session->userdata('USER_EMAIL'));
$query = $this->db->get('clocked_in_users');
if($query->num_rows() == 1){
echo "Already Clocked in";
exit;
}else{
$this->model_users->clock_user_in();
};
redirect('main/members');
}
Run Code Online (Sandbox Code Playgroud)
和我的观点:
<!DOCTYPE html>
<html lang="en">
<body>
<div class="container">
<h1>Members</h1>
<?php
echo "<pre>";
print_r ($this->session->all_userdata()); //displays all user session data.
echo "</pre>";
$this->load->helper('date');
echo "<h2>";
echo $date = date('Y-m-d H:i:s');
echo "</h2>";
?>
<a href="<?php echo 'clock_in'?>">Clock In</a>
<!-- clock in button -->
<br />
<br />
<a href="<?php echo 'clock_out'?>">Clock Out</a>
<br />
<br …Run Code Online (Sandbox Code Playgroud) 我如何将其转换为codeigniter?
我调用链接的PHP代码就是这个
<ul>
<li><a href="index.php?option=register">Register Here</a>
<li><a href="index.php?option=login">Login</a>
</ul>
Run Code Online (Sandbox Code Playgroud)
当我这称呼时,将调用此特定链接.
<?php
@$opt = $_GET['option'];
if($opt=="") {
include('register.php');
error_reporting(1);
} else {
switch($opt) {
case 'register':
include('register.php');
break;
case 'login':
include('login.php');
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在代码点火器中做到这一点.请帮我
我正在尝试使用Bootstrap 3.3.6提供的glyphicons,但Chrome阻止了对它们的访问,并显示以下错误消息:
来自" http:// [:: 1] "的字体已被跨源资源共享策略阻止加载:请求的资源上没有"Access-Control-Allow-Origin"标头.原产地" :HTTP //本地主机,因此"是不允许访问.
这是我的.htaccess:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我编辑错了.htaccess吗?
我也尝试header("Access-Control-Allow-Origin: *");在我的header.php文件开头添加,但这也不起作用.我没有想法.
文件夹结构如下:
application
controller
model
view
header.php
index.php
footer.php
.htaccess
system
assets
css
fonts
images
js
Run Code Online (Sandbox Code Playgroud) 我正在使用codeigniter,尝试在where子句中使用数组,并且仅返回与该数组匹配的id。
提交表格:
$arrTID = $this->input->post('Present');
print_r($arrTID);
输出:
Array(
[0]=>FMM003
[1]=>30089
[2]=>30097
)
Run Code Online (Sandbox Code Playgroud)
在foreach中使用时:
foreach($arrTID as $key=>$ID){
print_r($ID);
}
Run Code Online (Sandbox Code Playgroud)
输出:FMM0033008930097
查询:
$query = $this->db->query("select TraineeID from tbl_attendance_processed where TraineeID IN $ID and attnDate='$atnDate'");
$res=$query->result_array();
Run Code Online (Sandbox Code Playgroud)
我实际上需要该查询返回与该查询匹配的数组中的ID。怎么得到这个?
codeigniter ×10
php ×8
mysql ×2
cors ×1
csv ×1
echo ×1
ffmpeg ×1
file-upload ×1
import ×1
join ×1