我正在从MySQL查询中动态创建一个表.出于某种原因,下面的'notes'字段只返回字符串的第一个单词,虽然当我用echo($notes)它测试它时显示就好了. $status同样设置,也很好.我错过了什么?我假设它与使用值预填充文本字段有关.我正在使用codeigniter.
$notes = empty($row["notes"]) ? "None" : $row["notes"];
echo($notes);
echo('
<tr class="even">
<td class="status-icons">'.$error_level.'</td>
<td>'.$row["name"].'</td>
<td>'.$status.'</td>
<td class="notes-col">
<input type="text" name="submit_notes" value='.$notes.' class="notes-copy">
</td>
</tr>'
Run Code Online (Sandbox Code Playgroud) 我已经设置了一个codeigniter环境。我能够将数据从我的欢迎控制器传递到视图,但是我创建了一个名为TestController的新控制器,但无法将数据传递到测试视图。它说未定义的变量。
遇到PHP错误
严重程度:注意
消息:未定义的变量:数据
文件名:views / gallery.php
行号:4
<?php
class Testcontroller extends CI_Controller {
// --------------------------------------------------------------------
/**
* The constructor
*/
function __construct()
{
parent::__construct();
}
function index() {
$data = array('title' => 'My Title',
'heading' => 'My Heading',
'message' => 'My Message');
$this->load->view('test', $data);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
<?php var_dump($data); ?>
Run Code Online (Sandbox Code Playgroud)
我是CodeIgniter的新手.在模型中,我有以下代码:
public function get_all_subjects()
{
return $this->db->get('subjects');
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,我有:
public function index()
{
$this->load->model('subjects');
$data['content'] = $this->subjects->get_all_subjects();
$this->load->view('home', $data);
}
Run Code Online (Sandbox Code Playgroud)
我试图在视图中获取值:
foreach($content as $val)
{
echo $val['subject']; //i am getting error, Message: Undefined index: subject
}
Run Code Online (Sandbox Code Playgroud)
subjects表中的字段是subject_id和subject.
我收到此错误消息:
未定义的索引:主题
任何人请帮助我检索数据库数据以及如何在html table中查看它.我给出的编码是否正确,如果没有,请你说我要如何给.为了在html表中查看它.
调节器
class edit_content extends CI_Controller {
function edit_content()
{
parent::__construct();
$this->load->model('editcontent_model');
$this->load->helper('url');
$this->load->library('acl');
$this->data = $this->editcontent_model->get_contents();
}
}
Run Code Online (Sandbox Code Playgroud)
视图
<table>
<tr>
<th>Content</th>
</tr>
<?php foreach($this->data as $r): ?>
<tr>
<tr><?php echo $r['content']; ?>
</tr>
<?php endforeach; ?>
<table>
Run Code Online (Sandbox Code Playgroud)
模型
class editcontent_model extends CI_Model {
var $CI;
function editcontent_model(){
parent::__construct();
}
function get_contents() {
$this->db->select('content');
$this->db->from('contents');
$query = $this->db->get();
return $result = $query->result();
$this->load->view('edit_content/edit_content', $result);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个要求我需要将数据插入到不同数据库的两个表中.
$insert_query = 'INSERT INTO table1 (col1, col2) values(1, 2)';
$insert_otherdb_query= 'INSERT INTO otherdb.table1 (col1, col2) values(1, 2)';
$this->db->query($insert_query); //works fine
$this->db->query($insert_otherdb_query); //doesn't work
Run Code Online (Sandbox Code Playgroud)
错误
表'mydb.otherdb.table1'不存在
它不会忽略mydb这是我的默认数据库...
任何suggesstions?
在使用活动记录时,如何忽略codeigniter中的反引号?我需要按案件订购
case when roll_number is null then 1 else 0 end,
Run Code Online (Sandbox Code Playgroud)
哪个代码点火器使它成为
ORDER BY `case` when roll_number is null then 1 else 0 end
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误.请帮忙
在我将第一个(CodeIgniter)应用程序放在Github上之前,我对CodeIgniter .gitignore文件有疑问(见下文).我的config目录中没有开发目录.我可以.gitignore */config/*代替吗?config目录中开发目录的重要性是什么?
*/config/development
*/logs/log-*.php
*/logs/!index.html
*/cache/*
*/cache/!index.html
Run Code Online (Sandbox Code Playgroud) 我想从客户端(jquery)端向服务器端(php-codeigniter)发送2个参数.参数是id(整数)和text(字符串).我试过了:
window.location.href="AjaxUpdate/sendMessage/"+id+"/"+text;
Run Code Online (Sandbox Code Playgroud)
过去只使用id对我有用,但因为文本字符串可以有空格我可以得到:
http://localhost/b1/mycontroller/myfunction/3/gdfgdgd%20 %20 gd
Run Code Online (Sandbox Code Playgroud)
这使:
An Error Was Encountered
The URI you submitted has disallowed characters.
Run Code Online (Sandbox Code Playgroud)
使用jquery准备和传输字符串到服务器端的最佳方法是什么?我假设ajax将以某种方式使用
我想要做的是使用sum如果在codeigniter中,当我在浏览器中运行时它有错误,但我在MYSQL中查询,没有错误并且工作得很好.
这是我的代码
$this->db->select('sum(if(`monitoring_type` = 1,1,0)) AS independent,sum(if(`monitoring_type` = 2,1,0)) AS buddy,count(*) AS TM, rate_info.qm_title');
$this->db->from('qm.recordings');
$this->db->join('qm.rate_info', 'recordings.record_id = rate_info.record_id');
$query = $this->db->get();
return $query->result();
Run Code Online (Sandbox Code Playgroud)
我的错误

MYSQL

[编辑]:如何在codeigniter的路径中删除"index.php"的 副本
[那里的解决方案对我不起作用]
我是第一次尝试codeigniter而且我还是非常新的php.我想从我的网址中删除index.php.
安装的代码点火器
取代了我自己的index.php
我的.htaccess中有这个
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user …Run Code Online (Sandbox Code Playgroud)