我有这个代码:
$dbInstance = DB_Instance::getDBO();
$statement = $dbInstance->prepare("SELECT id, name FROM language ORDER BY id");
$statement->execute();
$rows = $statement->fetchAll();
//Create associative array wuth id set as an index in array
$languages = array();
foreach($rows as $r) {
$languages[$r['id']] = $r['name'];
}
return $languages;
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何使用PDO语句来实现数组$ languages产生的相同结果.我尝试了一些不同的fetch_styles.
我尝试了一些不同的风格,我可以这样:
[0] svenska
[1] engelska
Run Code Online (Sandbox Code Playgroud)
但我想要:
[1] svenska
[2] engelska
Run Code Online (Sandbox Code Playgroud)
(其中1和2是数据库中id的值)
我想我可以创建一个函数并调用它,FETCH_FUNC
但我不确定它会如此之大.
以上是最好/最干净的方法吗?
我想知道是否有一种完全禁用用户注册的方法?我有一个真正无需添加用户的客户端.对我而言,这将是一种极端的安全措施.当然,我必须能够通过代码或类似的方式添加用户.
有没有办法实现这个目标?
如何使用jQuery获取图像的html?
我希望这作为输出:
<img src="pokerface.png" alt="pokerface" />
Run Code Online (Sandbox Code Playgroud)
我正在尝试这个,但我得到一个空字符串(或null):
var imageHtml = $("#user-dialog .product-item img").html();
Run Code Online (Sandbox Code Playgroud)
以下返回Object,但我想要html
var imageHtml = $("#user-dialog .product-item img")
Run Code Online (Sandbox Code Playgroud)
我怎么做?
如果我尝试
var imageHtml = $("#user-dialog .product-item img").attr("src");
Run Code Online (Sandbox Code Playgroud)
我得到了正确的图像源(pokerface.png
),所以我知道它是正确的元素.
我的数据库中有大约 10-15 个数字,精度为 1、2 或 3 位小数,有符号和无符号。
正在使用的数据类型示例:
decimal(10,3), decimal(10,2), decimal(10,1)
Run Code Online (Sandbox Code Playgroud)
我在 PHP 中计算它们是这样的:
$result = ($value1from_col1 + ($value2from_col2 * 30)/500) * 0.453;
Run Code Online (Sandbox Code Playgroud)
然后我使用一些这样的round()
功能:
$result_round = round($result, 2, PHP_ROUND_HALF_UP);
Run Code Online (Sandbox Code Playgroud)
结果$result_round
最大:100.000,999
我正在检查:多少精度的 bcmath PHP 库? 并且答案指出,如果您不使用 round()、printf 等函数,这不会成为问题。
那么我应该使用 BCMath-extension 吗?(只是因为我正在使用round()
)
是否有可能显示设置为溢出的div的内部"顶部":隐藏?
就像是:
<div style="position:relative;overflow:hidden;" id="container">
<div style="position:absolute;left:-15px;width:100px;height:100px;" class="product">product1</div>
<div class="product-popup">Product1 price etc</div>
<div style="position:absolute;left:10px;width:100px;height:100px;" class="product">product2</div>
<div class="product-popup">Product2 price etc</div>
</div>
Run Code Online (Sandbox Code Playgroud)
查看页面时,产品在#container
-div 边界外不可见.当我点击带有类的div时,product-popup
我想在#container
-div 的边界外显示弹出窗口.这可能吗?
禁用交易有什么意义? http://ellislab.com/codeigniter/user-guide/database/transactions.html
$this->db->trans_off()
Run Code Online (Sandbox Code Playgroud)
我看不出用法.是用于测试目的吗?
"当禁用事务时,您的查询将自动提交,就像在没有事务的情况下运行查询时一样."
我有一个表user
,其中存在一个列nameOfUser
.nameOfUser2
-列不不存在.
TEST1 此代码将尝试使用正常事务执行2次插入:
$this->db->trans_start();
$this->db->insert('user', array('nameOfUser' => 'testCVVCOOL'));
$this->db->insert('user', array('nameOfUser2' => 'test2'));
$this->db->trans_complete();
Run Code Online (Sandbox Code Playgroud)
但它被回滚(没有插入任何内容),因为nameOfUser2
第二个插入中不存在列列.
TEST2 此代码将尝试在禁用事务的情况下执行2次插入
$this->db->trans_off();
$this->db->trans_start();
$this->db->insert('user', array('nameOfUser' => 'testCVVCOOL'));
$this->db->insert('user', array('nameOfUser2' => 'test2'));
$this->db->trans_complete();
Run Code Online (Sandbox Code Playgroud)
上面会将testCVVCOOL字符串插入-table,user
即使第二个插入中有错误($this->db->insert('user', array('nameOfUser2' => 'test2'));
)
您何时需要以这种方式禁用交易?
我有几个产品与z-index相互重叠.
我试过这个.
$(document).on('mouseover', '.product', function(e) {
prod_id = $(this).attr('id'); //Each product has an id
prod_zindex = $(this).css('z-index'); //Store z-index when hovered
$(this).css('z-index',50000000);
});
//Restore z-index when moving from product
$(document).on('mouseout', '.product', function(e) {
$('#' + prod_id ).css('z-index',prod_zindex);
});
Run Code Online (Sandbox Code Playgroud)
prod_id
并且prod_zindex
是全局变量
我想要发生的事情是,应该将悬停的产品设置为最高的z-index,但是当我离开时,我希望将更改的z-index恢复为原始的z-index.
显然我做错了什么.我想这是因为我无法控制mouseover/mouseout - 事件将要执行的顺序.
处理这种情况的最佳方法是什么?产品的"原始"状态类似于z-index = 0,z-index = 1,z-index = 2等.
请给我任何提示/指示......
UPDATE
澄清:
在正常情况下我可以.product:hover
在css中使用,但在这种情况下它将没有效果,因为z-index在每个产品上都是内联设置的(并且它必须是这样的)
我在本地开发环境上有此数据库配置
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = ''; //Actual username is put inside these quotes
$db['default']['password'] = '';
$db['default']['database'] = ''; //Actual name of database is put inside quotes
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = APPPATH .'cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Run Code Online (Sandbox Code Playgroud)
当我将其转移到生产服务器时,它不起作用,因此我尝试了很多事情,但是有一件事seemed to work
是将dbdriver更改为mysqli而不是mysqli。但是我也不得不将db_debug设置为FALSE(因此“有效”不是正确的声明)
我已经读过很多,但是在任何地方都找不到答案。(我不满意:“更改为debug = false,它将起作用”)
我想看看实际的问题是什么,所以我也将本地服务器也更改为mysqli驱动程序,然后出现错误:
A Database Error Occurred
Unable …
Run Code Online (Sandbox Code Playgroud) 我正在使用https://wordpress.org/plugins/wp-session-manager/插件,如果我只是设置并获取变量,它就可以工作.(所以实际的会话管理工作)
我想要的是在ajax调用和"浏览器的正常请求"之间交换会话数据.这甚至可能吗?
的functions.php
add_action( 'wp_ajax_nopriv_set_formvalues', array ('FormHandler', 'set_formvalues') );
add_action( 'wp_ajax_set_formvalues', array ('FormHandler', 'set_formvalues') );
//Use of Plugin WP Session manager (so we can use sessions for storing current form values)
//(do this with ajax before submitting the form)
global $wp_session;
$wp_session = WP_Session::get_instance();
$formhandler = new FormHandler();
class FormHandler {
public function get_current_formvalues() {
return $wp_session['formvalues'];
}
public function set_formvalues() {
//Default values for form
$formvalues = array('name' => '',
'address' => '',
'plz' => '',
'city' …
Run Code Online (Sandbox Code Playgroud) 尝试找出如何以合理的方式在 php 中使用过滤器
//Do sanization of user input
//$_POST['amount_ecb'] can be 77,7 or 77.7
$amount = filter_input(INPUT_POST, 'amount_ecb',
FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
Run Code Online (Sandbox Code Playgroud)
如果发布的值为 77.7,它会正确设置金额,但如果用户使用逗号而不是点设置数字(例如 77,7),$amount
则返回 77
我希望它在这两种情况下都返回 77.7。可以用过滤器解决这个问题吗?
更新 反馈后(发布答案)我仍然有同样的问题:
使用时
$_POST['amount_ecb'] = str_replace(',', '.', $_POST['amount_ecb']);
Run Code Online (Sandbox Code Playgroud)
前
这是它返回的
$_POST 对象
array (size=5)
'amount_ecb' => string '77.7' (length=4)
'from_ecb' => string 'GBP' (length=3)
'to_ecb' => string 'SEK' (length=3)
'submit' => string 'Calculate currency' (length=18)
'result_decimals' => string '4' (length=1)
Run Code Online (Sandbox Code Playgroud)
$金额
string '777' (length=3)
Run Code Online (Sandbox Code Playgroud) php ×4
jquery ×3
wordpress ×3
codeigniter ×2
css ×2
html ×2
activerecord ×1
ajax ×1
arrays ×1
associative ×1
bcmath ×1
filtering ×1
hover ×1
image ×1
mysqli ×1
overflow ×1
pdo ×1
transactions ×1
z-index ×1