is_int() and is_string() Do Not Work As Expected In PHP

is_int() returns TRUE if the variable passed in is an integer, which may sound similar to is_numeric(). However, data passed in through a form or from MySQL query, even if numeric in content, is of type string, which means that is_int() will fail. Is_numeric(), on the other hand, returns true if the variable is a number or if it is a string containing a number also. This same problem applies to is_float(), as floating-point values set from user input are typed as strings. On contrast, when numeric data passed through a form or from MySQL query, is_string() does return TRUE.

This feature makes is_int() and is_string() next to useless.


http://www.tuxradar.com/practicalphp/7/7/3

Is_numeric() Is Not Good Enough in PHP

It supposes good enough. However, it fails in following circumstances:

1. In some machines number 0 returns false.
2. Unable to detect ‘+.1’ as numeric.
3. When number flagged as string in database, it returns true. Well, it is not in_numeric’s fault since it is designed that way.
4. However, when six digits number is hexadecimal number for color code in HTML, it would for sure stored in database as string, which does cause the problem.

Solutions:
For 1, If (is_numeric($para) || 0==$para))
For 2, no simple solution as good as enough
For 3, no solution
For 4, store hexadecimal number with # in front in database.


http://stackoverflow.com/questions/2774472/php-is-numeric-returns-false-on-0

Parameter Management

Sometimes complex function may have excessive number of parameters. This does cause the usability issue for function callers. There is an easy way to handle this by put all parameters into an associative array. Here is an example in JavaScript:

; function example (config)
{
; var p = {para1:0, para2:'', para3:1}
; for (var i in p) p[i] = ('undefined'==typeof config[i]) ? p[i] : config[i]

// Use p['para1'] instead para1 as variable in codes.
}

The function caller would be:

; example ({para2:'newArgument'})

The beauty of it is not only the unneeded parameters can be omitted, but also sequence of the parameters, since it is an associative array. In addition, it does provide a meaningful array key.

This concept can be used in almost all languages.

Date Format of Parameters for SSRS

While SQL Server does accept the date format as string, it is suggested to convert it to datetime data type. This will allow you to use a calendar control as well as avoiding any date format errors that may occur when running your query. Indeed, it does cause minor errors internally. The period, it can be:

t.add_datetime >= @StartDate AND t.add_datetime < DATEADD(D, 1, @EndDate)

The trick here is for general public both dates should be inclusive. Above code indeed includes the time from 0:00:00 of the StartDate to 23:59:59 of the EndDate.


http://www.sqlusa.com/bestpractices/datetimeconversion/

Public, Private, Protected, Static Function

Public - Available to everyone who can access the class. If a function without declared as private or protected, it is public. In PHP, when variable is declared with keyword 'var', it is declared as public.

Private - Available only within the class where the function/variable is declared.

Protected - Available only within the class, or any class that is derived from the class, or called inherited.

Dynamic - Can only be called after create an object (instantiation) from the class. If a function without declared as static, it is dynamic.

Static - Can be called without creating an object (instantiation) from the class.


http://www.daniweb.com/forums/thread285410.html
http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-3.php

Build an Uneven Nested Multidimentional Array in PHP

Build an uneven nested multidimensional array in PHP is very useful since you can retrieve the dataset mixed up by data from main table database and the affiliate tables, in which they are in primary and foreign key relationship. The beauty of it is you can retrieve it once for all and the data within the array maintain the same primary and foreign key relationship as they are in database. To append affiliate array into main array can use:

array_merge($mainArray, $affliateArray);

When declare the $affliateArray, it is better to give it a unique key, for instance 'appendix' below:

$affliateArray = array(array(array( "font_cd" => 'S'
, "font_color" => '000000'
)
)
);

$affliateArray['mainArrayDimension']['appendix'] = array( "font_cd" => $newCode
, "font_color" => $newColore
);

Sure, it would increase a dimension. However, it would clearly distinct the keys affiliate array from the keys in main array. Please note, it is preferred to use array_merge() than array_push() for easy maintain the main array's dimension.

The purpose of this rather complicated arrangement is not only one is able to preserve the primary and foreign key relationship in database, but also all child records in database, into a denormalized data structure in array.


http://www.java-samples.com/showtutorial.php?tutorialid=997

Newline and Tab in Text Fields in SSRS 2005

Both Newline (by press Enter in keyboard) and Tab does not work in either textbox or text fields in SQL Server Reporting Services 2005, despite it looks you can set this in Tools->Options->Text Editor->Basic->Tabs. There is no such problem in SSRS 2008.

Ctri+Shit+Enter will enable to insert Newline. It appears no fix for Tab. Someone suggested using multiple textboxes or table to arrange the indenting.

Error Message: The report definition is not valid. Details: The report definition has an invalid target namespace

Full error message is: The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded.

According to Microsoft, one "cannot publish a report defined in the SSRS 2008 RDL schema to a SSRS 2005 report server." It is true. In one case, it happened when report was defined in Microsoft Visual Studio 2008 (SQL Server Business Intelligence Development Studio) and the SSRS is 2005.

The easiest possible solution is to install Microsoft Visual Studio 2005, because both 2005 and 2008 can co-exist in one machine.


http://connect.microsoft.com/VisualStudio/feedback/details/361103/reporting-services-report-cant-deploy-to-sql-2005

Labels