假设我将我的整个网站CSS放在1个css文件中,所以它相当大,我想知道一个页面是否使用3个类,如下所示从服务器请求3个图像,让我们说有50个这样的东西在整个css文件中,每个人都可以从服务器调用/请求,还是只需要页面需要的3个?
background-image:url(http://localhost/images/btn3.gif);
Run Code Online (Sandbox Code Playgroud) 我试图将mysql DATETIME转换为这种格式m/d/y,但下面的代码不起作用,返回12/31/1969而不是有人能告诉我如何做到这一点?
$fromMYSQL = '2007-10-17 21:46:59'; //this is the result from mysql DATETIME field
echo date("m/d/Y", $fromMYSQL);
Run Code Online (Sandbox Code Playgroud) 我正在使用注册表单,我正在使用PHP,在我的处理部分我运行一些代码,如果提交的项目失败,我将其添加到errors数组.
下面是一段代码,我正处于需要找到最佳方法来确定是否应该触发错误的地方.
因此,如果错误数组中设置了一个值,那么我需要重定向并执行其他一些操作.
我正在考虑使用isset
或者其他is_array
但我不认为这是答案,因为我设置数组使用**$signup_errors = array()**
不会这样做is_array
是真的吗?
任何人都可以建议一个好方法吗?
//at the beginning I set the error array
$signup_errors = array();
// I then add items to the error array as needed like this...
$signup_errors['captcha'] = 'Please Enter the Correct Security Code';
Run Code Online (Sandbox Code Playgroud) 我知道通常情况下,构建mysql查询以命名您需要的每个项目总是更好的性能但是例如在个人资料页面上我可能需要除了少数几个项目之外的所有项目.
SELECT user_name,f_name,l_name,country,usa_state,other_state,zip_code,city,gender,birth_date,date_created,date_last_visit,
user_role,photo_url,user_status,friend_count,comment_count,forum_post_count,referral_count,referral_count_total,
setting_public_profile,setting_online,profile_purpose,profile_height,profile_body_type,profile_ethnicity, profile_occupation,profile_marital_status,profile_sex_orientation,profile_home_town,profile_religion,
profile_smoker,profile_drinker,profile_kids,profile_education,profile_income,profile_headline,profile_about_me,
profile_like_to_meet,profile_interest,profile_music,profile_television,profile_books,profile_heroes,profile_here_for,profile_counter FROM users WHERE user_id=1 AND user_role >
Run Code Online (Sandbox Code Playgroud)
因此,如果没有进行大量测试,也许有经验丰富的人可以提出一些建议吗?
这会更糟吗?
SELECT * FROM users WHERE user_id=1 AND user_role >
Run Code Online (Sandbox Code Playgroud)
我更喜欢列出所有项目,因为在那个页面上,如果我需要来自数据库的东西,但是如果它会更快,我就不会列出它们,这很容易看到我可以使用的东西.
我曾经研究过在PHP中使用命名空间,但最近看了一个使用该use
关键字的项目,然后访问了命名空间对象,好像它们没有命名空间一样正常.
我的问题是,下面是正确的代码,它HS文件index.php
,并使用该命名空间MyLibrary\Base
,然后它使用use
带来的\MyLibrary\Registry
\MyLibrary\User
,并\MyLibrary\Request
然后它可以访问任何这些对象而不在它们前面放置命名空间,因此该use
部分下面的实际代码看起来像一个普通的命名空间前php文件.
我问你是否使用命名空间?或者我错过了什么?
文件:index.php
<?php
namespace MyLibrary\Base;
use \MyLibrary\Registry;
use \MyLibrary\User;
use \MyLibrary\Request;
class Base
{
public $registry;
function __construct($registry)
{
$this->registry = $registry;
$this->user = New User;
$this->request = new Request;
# code...
}
}
?>
Run Code Online (Sandbox Code Playgroud)
文件:registry.class.php
<?php
namespace MyLibrary\Registry;
class Registry
{
public $user;
function __construct($user)
{
$this->user = $user;
# code...
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我已经使用HTML并使用jQuery将基本示例任务列表表入侵.我附上了一些on change
事件给我Filter DropDown Selection Fields
演示:http://codepen.io/jasondavis/pen/MwOwMX?edit = 101
我有一个过滤器选择字段为每个:
他们独立地努力完成工作,从我的任务列表中过滤掉不匹配的结果.
对于每个任务行,我将每个可过滤选项的值存储在Data Attribute
类似于此示例的任务行HTML中:
<tr id="task-3"
class="task-list-row"
data-task-id="3"
data-assigned-user="Donald"
data-status="Not Started"
data-milestone="Milestone 1"
data-priority="Low"
data-tags="Tag 3">
<td>Task title 3</td>
<td>11/16/2014</td>
<td>02/29/2015</td>
<td>Low</td>
<td>Milestone 1</td>
<td>Donald</td>
<td>Tag 3</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
因此,任务行的实际文本无关紧要,因为任务行不会显示所有属性.重要的是存储在任务行数据属性中的值.
具有Miledstone
设置为的任务行/记录Milestone 2
将具有这样的数据属性data-milestone="Milestone 2"
一个示例JavaScript/jQuery Filter代码:
// Task Milestone Dropdown Filter
$('#milestone-filter').on('change', function() {
var taskMilestone = this.value;
if(taskMilestone === 'None'){
$('.task-list-row').hide().filter(function() {
return …
Run Code Online (Sandbox Code Playgroud) 我通常在jquery中使用它
$(document).ready(function() {
//stuff
}
Run Code Online (Sandbox Code Playgroud)
我只是在一个大量使用jquery的网站上,他们称之为使用
$j(document).ready(function() {
//stuff
}
Run Code Online (Sandbox Code Playgroud)
在这个网站上,他们开始几乎所有的东西与j ...
function PostComment(form) {
form = $j(form);
$j('#CommentSubmitButton').hide();
$j('#CommentInProgress').show();
$j.post('/utils/ajaxhandler.aspx', form.serialize(), function(data) {
$j('#CommentInProgress').hide();
$j('#CommentSubmitButton').show();
});
}
Run Code Online (Sandbox Code Playgroud)
这只是另一种方式,还是依赖于不同版本的jquery或其他?
我应该在MySQL中使用大整数还是常规整数来存储timerstamp?我计划将它存储在INT而不是内置的时间戳或日期时间中,以便我应该使用哪种INT类型?
我想听听别人对此的看法?目前,我在头文件类型文件中创建一个mysql数据库连接,然后将其包含在我站点的每个页面的顶部.然后,我可以在该1个打开的连接上运行尽可能多的查询.如果页面是由包含的6个文件构建的,并且有15个不同的mysql查询,那么它们都将在这个1连接上运行.
现在有时我会看到创建多个连接的类,例如每个查询一个.
使用一种方法比另一种方法有什么好处吗?我认为1连接比多个好,但我可能是错的?
在用PHP编写对象时,我总是很难理解Interfaces的真正价值(可能是我想象的其他语言)
根据我的理解,你使用一个Interface
来强制或保证当一个类使用Interface
该类时,该类将具有在Interface
该类内部定义的方法.
因此,根据我对使用它们的小知识,这并不意味着Interface
在定义超过1个需要这些方法的类时,您只会找到一个有益的东西吗?
更清楚的是,如果我有一个类做了一件事而没有其他类需要做那样的事情,那么Interface
在那个类上使用它是没有意义的吗?
所以你不会Interface
在每个课上使用一个对吗?
PS)如果你投票这个问题,exact duplicate
那么你没有阅读问题,只有标题,因为我已经阅读了大部分类似的问题
php ×5
mysql ×3
jquery ×2
arrays ×1
biginteger ×1
css ×1
database ×1
datetime ×1
filter ×1
integer ×1
interface ×1
javascript ×1
namespaces ×1
oop ×1
performance ×1
sql ×1