我认为这可以通过该.prev()功能实现,但由于某种原因它无法正常工作.
我正在为博客上的帖子创建拇指向上/向下按钮.我正在尝试根据用户投票显示消息.无论是向上还是向下,但只要我投票1个特定帖子,就会显示所有帖子的消息.
这是我的代码.我删除了prev()尝试以使其更具可读性.该脚本工作正常ajax明智.
$(document).ready(function() {
$(".vote_button").click(function(e) { //the UP or DOWN vote button
var vote_status = $(this).attr('class').split(' ')[1]; //gets second class name following vote_button
var vote_post_id = $(this).attr("id"); //the post ID
var dataString = 'post_id=' + vote_post_id + '&vote_status=' + vote_status;
$.ajax({
type: "POST",
url: "url/add_vote.php",
data: dataString,
cache: false,
success: function(html) {
if (vote_status == 1)
{
$('.msg_box').fadeIn(200);
$('.msg_box').text('You voted UP!');
}
if (vote_status == 2)
{
$('.msg_box').fadeIn(200);
$('.msg_box').text('You voted DOWN!');
}
}
});
return false;
}); …Run Code Online (Sandbox Code Playgroud) 以下所有命令均有效,但从安全性,兼容性,速度和其他约定的角度来看,哪个命令正确?
//one
echo "$row->first_name $row->last_name <br />";
//two
echo $row->first_name . ' ' . $row->last_name .'<br />';
//three
echo $row->first_name;
echo $row->last_name;
echo '<br />';
Run Code Online (Sandbox Code Playgroud) 我UNIQUE Constraint在我的表中使用两列来防止重复行.如果我尝试插入具有相同2列的行,我会得到
发生数据库错误错误号:1062
关键'订阅'重复输入'62 -88'
INSERT INTO
subscriptions(user_id,subscribed_to,date)VALUES( '62', '88', '2011-07-11 19时15分13秒')文件名:C:\ wamp\www\mysite\system\database\DB_driver.php
行号:330
如何返回php错误,e..g Already subscribed!而不是显示mysql错误?
我的表单中有2个提交按钮,我试图让每个按钮都使用不同的控制器方法.我试图避免使用多种形式.
我正在使用
<button type="submit" onclick="javascript: form.action='restore'">Restore</button>
<button type="submit" onclick="javascript: form.action='delete'">Delete</button>
Run Code Online (Sandbox Code Playgroud)
...哪个有效,但我不确定这是不是最好的方法.有什么想法吗?
我正在将文件上传到 Amazon S3,不需要将它们存储在本地。我不想使用unlink()或 cron 作业,而是想将文件添加到tmp文件夹中并将它们从那里发送到 Amazon S3。我尝试在配置选项中指定路径:
$tmp = ini_get('upload_tmp_dir');
$config['upload_path'] = $tmp;
Run Code Online (Sandbox Code Playgroud)
我收到上传错误:
The upload destination folder does not appear to be writable.
我将 tmp 文件夹设置为可写,但仍然出现错误。有谁知道如何使用 CI 上传库上传到 tmp 文件夹?恐怕我可能必须修改核心上传库,删除所有上传路径功能。
我知道我可以使用以下方法获取数组中的最后一项:
_.nth(arr, -1)
要么 arr[arr.length - 1]
要么 arr.slice().pop()
还有很多...
如何获取索引呢?
我的数组如下所示:
[
{ icon: 'twitter', url: '#'},
{ icon: 'facebook', url: '#'},
{ icon: 'instagram', url: '#'},
],
Run Code Online (Sandbox Code Playgroud)
我如何获得最后一项的索引?我试图找到最简单的单行解决方案,而不使用map或循环。
注意:如果有的话,ReactJS解决方案也可以接受。
我正在查询数据库中是否存在与url段中传递的id匹配的单个记录www.site.com/post/24.
假设帖子24不存在.什么是安全和seo兼容的方式来处理未找到的数据库请求?
以下是使用Codeigniter模型的当前解决方案:
function read_post($post_id) //argument is the value of the url segment
{
$user_id = $this->tank_auth->get_user_id();
$this->db->where('user_id', $user_id);
$this->db->where('post_id', $post_id);
$this->db->limit(1);
$query = $this->db->get('posts');
//check if record exists
if ($query->num_rows() > 0) //row is returned
{
return $query->row(); //passed to controller and view
}
else
{
show_404(); //generate 404 message
return FALSE; //------------------------or exit()?
}
}
Run Code Online (Sandbox Code Playgroud)
请分享您自己最好的方法/意见.
我有一个名为的数据库表Categories.我想创建一个包含db中所有类别的表单下拉列表.我的解决方案是创建一个关联数组并将其添加到form_dropdown()函数的第二个参数中.我的结果是一个不需要的多维数组.
模型:
function list_categories()
{
$user_id = $this->tank_auth->get_user_id();
$this->db->where('user_id', $user_id);
$this->db->order_by("date_created", "desc");
$query = $this->db->get('categories');
return $query;
}
Run Code Online (Sandbox Code Playgroud)
视图:
//create array
$categories = array();
if ($query->num_rows() > 0)
{
$categories = $query->result_array();
}
//create dropdown
echo form_dropdown('category', $categories, $date_created); //selected value based date created
Run Code Online (Sandbox Code Playgroud)
代码给出了一个多维数组
Array (
[0] => Array ( [cat_id] => 27 [user_id] => 3 [cat_title] => Some Title [status] => 0 [date_created] => 2012-06-22 18:48:14 )
[1] => Array ( [cat_id] => 24 …Run Code Online (Sandbox Code Playgroud) 是否可以默认打开所有信息窗口.我尝试了以下但它不起作用:
var infowindow = new google.maps.InfoWindow({
maxWidth: 160
});
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: icons[iconCounter]
});
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
Run Code Online (Sandbox Code Playgroud) 在以下示例句子中:
绿色衬衫绿色帽子
是否可以使用正则表达式来检测2个相同的单词并将第二个单词替换为and:
绿色衬衫和帽子
一个更难的字符串示例.这里需要替换第一个相同的单词:
你是一位具有艺术天赋的音乐天才
应该成为:
你是一个有艺术和音乐天赋的人
php ×6
javascript ×5
codeigniter ×4
arrays ×2
forms ×2
html ×2
mysql ×2
file-upload ×1
function ×1
google-maps ×1
jquery ×1
reactjs ×1
regex ×1
vote ×1