我正在考虑使用TIMESTAMP存储日期+时间,但我读到它有2038年的限制.我没有大量提出我的问题,而是倾向于将其分解成小部分,以便新手用户也能轻松理解.所以我的问题:
提前致谢.
我的平台:
PHP和mySQL
我的情况:
我遇到了一种情况,我需要在表格的一列中存储用户选择的值.现在我的选择是:
我的问题:
所以我想知道,以上两种类型中的哪一种:
访问该列时,可以提高查询速度(为简单起见,请不要混淆其他查询或访问其他列).
是最有效的存储和访问数据的方式,为什么?
如果列被索引,那么访问速度如何变化?
我的理解是,由于char(1)和tinyint(1)只占用1个字节的空间,因此在这种情况下存储空间不会成为问题.然后剩下的就是访问速度.据我所知,数字索引比其他任何东西都更快,更有效.但我认为,这里的情况很难决定.肯定希望听到你对这一次的体验.
先感谢您.
平台: PHP和mySQL
出于实验目的,我在自己的网站上尝试了一些XSS注射.考虑这种情况,我有我的表单textarea输入.由于这是一个textarea,我能够输入文本和各种(英文)字符.以下是我的观察:
一个).如果我只应用strip_tags和mysql_real_escape_string并且在将数据插入数据库之前不在我的输入上使用htmlentities,则查询会中断并且由于异常终止而导致显示我的表结构的错误.
B).如果我在将数据插入数据库之前在我的输入上应用strip_tags,mysql_real_escape_string和htmlentities,则查询不会中断,我能够成功地将textarea中的数据插入到我的数据库中.
所以我确实理解必须不惜一切代价使用,但不确定何时应该使用它.考虑到上述情况,我想知道:
什么时候应该使用htmlentities?它是应该在将数据插入数据库之前使用还是以某种方式将数据导入数据库然后在我尝试显示来自数据库的数据时应用htmlentities?
如果我按照上面B)中描述的方法(我认为这是我案例中最明显和最有效的解决方案),当我尝试显示数据库中的数据时,是否还需要应用htmlentities?如果是这样,为什么?如果没有,为什么不呢?我问这个问题,因为在我查看了这篇帖子之后,我真的很困惑:http://shiflett.org/blog/2005/dec/google-xss-example
然后还有一个名为html_entity_decode的 PHP函数.我是否可以使用它来显示我的数据来自DB(按照我的程序,如B点所示),因为我的输入应用了htmlentities?我应该选择哪一个:html_entity_decode和htmlentities以及何时?
预览页面:
我认为在这里添加一些特定情况的更具体细节可能会有所帮助.请考虑有一个"预览"页面.现在,当我从textarea提交输入时,Preview页面接收输入并显示html,同时隐藏的输入收集此输入.当点击预览按钮上的提交按钮时,来自隐藏输入的数据被POST到新页面,并且该页面将隐藏输入中包含的数据插入到数据库中.如果我在最初提交表单时不应用htmlentities(但仅应用strip_tags和mysql_real_escape_string)并且textarea中存在恶意输入,则隐藏的输入会被破坏,隐藏输入的最后几个字符会被视为  " />在页面上,这是不受欢迎的.因此,请记住这一点,我需要做一些事情以在预览页面上正确保留隐藏输入的完整性,然后收集隐藏输入中的数据,以便它不会破坏它.我该怎么做?对发布此信息的延迟表示道歉.
先感谢您.
在电子商务商店中:
主页上显示了一些项目,每个项目下面都有一个“添加到购物车”按钮。单击此按钮时,该项目将添加到购物车。如果再次单击此按钮,购物车中已存在的商品数量将增加 1。我相信这是循环。到现在为止还挺好。
在单一产品页面上,有一个“添加到购物车”按钮。单击此按钮时,该项目将添加到购物车。还有一个数量输入文本框,可用于更改数量。这也很好。
问题:
我需要区分 循环中单击的“添加到购物车”按钮(当前在主页上,但也可用于其他页面,例如存档页面等)与单击的“添加到购物车”按钮在单一产品页面上。基于这种区别,这是我需要做的:
$cart_item_key增加 1 并将其发送到将执行额外处理并保存详细信息的自定义函数再次购物车。$cart_item_key3,乘它,并将其发送到一个自定义函数,将做额外的处理和保存再次购物车的详细信息。我试过的:
我尝试了以下代码:
add_action('woocommerce_add_to_cart', 'custom_action_add_to_cart', 20, 6);
function custom_action_add_to_cart($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data)
{
    $cart = WC()->cart->get_cart();    
    $product = wc_get_product($product_id);
    // NEED TO RUN CUSTOM CODE HERE BASED ON THE CHECKS
    if (add to cart within loop is clicked) {
        // Get existing $quantity_from_cart from cart using $cart_item_key, but how???? 
        $new_quantity = $quantity_from_cart + …我正在尝试列出特定图书作者的所有book_sales信息.所以我有一个查询,并没有使用索引来查找记录.
以下是我的表格结构:
-- Table structure for table `books`
CREATE TABLE IF NOT EXISTS `books` (
  `book_id` int(11) NOT NULL auto_increment,
  `author_id` int(11) unsigned NOT NULL,
  `book_type_id` int(11) NOT NULL,
  `book_title` varchar(50) NOT NULL,
  `book_price` smallint(4) NOT NULL,
  `in_stock` char(1) NOT NULL,
  PRIMARY KEY  (`book_id`),
  KEY `book_type_id` (`book_type_id`),
  KEY `author_id` (`author_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- Dumping data for table `books`
INSERT INTO `books` (`book_id`, `author_id`, `book_type_id`, `book_title`, `book_price`, `in_stock`) VALUES
(1, 1, 1, 'My Book 1', 10, 'y'), …我的平台:
PHP和mySQL
我的情况:
我正在尝试在我的代码中实现事务.我试图按照例子,但它没有多大帮助.我正在运行3个查询,我想以这样的方式编写事务,这样如果任何查询失败,整个事务就应该回滚.我非常感谢一个简单,高效且非面向对象的PHP代码来实现这一目标.先感谢您.
我的PHP代码:
//db_res calls a custom function that performs a mysql_query on the query
$res1 = db_res("SELECT c1, c2 FROM t1 WHERE c5 = 3");
$res2 = db_res("UPDATE t2 SET c1 = 5 WHERE c2 = 10");
$res3 = db_res("DELETE FROM t3 WHERE c1 = 20");
if( $res1 && $res2 && $res3 )
{
 //commit --- but how?
}
else
{
 //rollback --- but how?
}
我的平台:
PHP和mySQL
我在这里:
我有4个表,即'books','book_type','book_categories','all_categories'.
我在做什么:
简单来说,我想显示库存中的所有书籍,即in_stock ='y',所有书中的书籍相关信息,只需一次,不重复输入.目前每本书都是重复的,我只想展示一次.
当前的问题:
在我的应用程序的前端,实际上当我希望它们只出现一次时(如在DISTINCT/UNIQUE中)并且不重复它们时,条目会反复显示.
我的怀疑:
我怀疑重复数据是因为每本书所属的类别.每个单一的图书条目都会多次显示,因为它属于一个类别.混乱?我的意思是,如果book1属于4个类别,那么book1将显示4次.如果book2属于2个类别,则显示2次.
我需要的:
我需要PHP和mySQL代码来解决上述问题.我希望我们可以在不使用mySQL中的GROUP_CONCAT的情况下解决问题,因为有相同的限制(1024?).一本书可以属于许多类别,我不想冒着使用GROUP_CONCAT丢失任何数据的风险.我还希望在单个查询中执行此操作,而无需在循环中重复访问数据库.感谢您的理解.
所有表和复制问题的相应数据如下:
CREATE TABLE IF NOT EXISTS `books` (
  `book_id` int(11) NOT NULL auto_increment,
  `book_type_id` int(11) NOT NULL,
  `book_title` varchar(50) NOT NULL,
  `book_price` smallint(4) NOT NULL,
  `in_stock` char(1) NOT NULL,
  PRIMARY KEY  (`book_id`),
  KEY `book_type_id` (`book_type_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `books`
--
INSERT INTO `books` (`book_id`, `book_type_id`, `book_title`, `book_price`, `in_stock`) VALUES
(1, 1, 'My Book 1', 10, 'y'), …我在我的页面中的textarea上使用TinyMCE.我试图获得字符和单词计数,并输入textarea.我一直在尝试各种版本,以使其正常工作,但没有成功.这是最新的越野车版本:
$().ready(function() {
    $('textarea.tinymce').tinymce({
        // Location of TinyMCE script
        script_url: 'jscripts/tiny_mce/tiny_mce.js',
        // General options
        theme: "advanced",
        plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
        // Theme options
        theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,
        // Example content CSS (should be your site CSS)
        content_css: "css/content.css",
        // Drop lists for link/image/media/template dialogs
        template_external_list_url: "lists/template_list.js",
        external_link_list_url: "lists/link_list.js",
        external_image_list_url: "lists/image_list.js",
        media_external_list_url: "lists/media_list.js",
        // Replace values for the template plugin
        template_replace_values: {
            username: "Some User",
            staffid: "991234"
        },
        //setup:'tmceWordcount'
        setup: function(ed) …我一直在尝试验证Checkbox set和Radio set并使用ng-messages指令显示错误消息但是它没有按预期工作.ng-messages根本不显示错误消息.我正在使用html文件填充错误消息.在解决错误之前,我的表单中将禁用提交按钮.
如何在以下情况下显示Checkbox集和Radio set的错误消息:
收音机中没有选择一个选项?
在Checkbox集中未选择至少一个选项?
检查Checkbox集的检查以便我们检查至少2个或更多,检查等等?
这是我的表格:
<form name="userForm" ng-submit="submitForm()" novalidate>
    <div class="form-group" ng-class="{ 'has-error' : userForm.subscribe.$invalid && !userForm.subscribe.$touched }">
        <label class="checkbox-inline">
            <input type="checkbox" id="subscribe1" value="option1" name="subscribe[]" ng-model="user.subscribe" required> 1
        </label>
        <label class="checkbox-inline">
            <input type="checkbox" id="subscribe2" value="option2" name="subscribe[]" ng-model="user.subscribe" required> 2
        </label>
        <label class="checkbox-inline">
            <input type="checkbox" id="subscribe3" value="option3" name="subscribe[]" ng-model="user.subscribe" required> 3
        </label>
        <div class="help-block" ng-messages="userForm.subscribe.$error" ng-show="userForm.subscribe.$invalid">
            <div ng-messages-include="home/messages.html"></div>
        </div>
    </div>
    <div class="form-group" ng-class="{ 'has-error' : userForm.gender.$invalid && !userForm.gender.$touched }">
        <div class="radio">
            <label>
                <input type="radio" name="gender" value="male" ng-model="user.gender" …我已通过以下方式向我的 WooCommerce 购物车收取特定费用:
WC()->cart->add_fee( __( "Delivery Fee"), 50);
上面代码的作用是,除了小计和运费之外,还将运费添加到总计中并正确显示总计。
我现在想以编程方式删除所申请的费用,但我无法这样做。
我尝试过这个,但它不起作用:
WC()->cart->remove_fees( __( "Delivery Fee"));
这是我的完整代码:
add_action( 'woocommerce_before_cart', 'custom_fees' );
function custom_fees() {
    // Add Fees - This WORKS
    WC()->cart->add_fee( __( "Delivery Fee"), 50);
    // Remove Fees - This DOES NOT WORK
    WC()->cart->remove_fees( __( "Delivery Fee"));
}
如何以编程方式删除所申请的费用,而无需清除购物车?
mysql ×6
php ×6
join ×2
jquery ×2
woocommerce ×2
wordpress ×2
angularjs ×1
char ×1
commit ×1
indexing ×1
javascript ×1
ng-messages ×1
rollback ×1
tinyint ×1
tinymce ×1
transactions ×1
year2038 ×1