Posts Tagged ‘values’

What is a Database?

Tuesday, September 30th, 2008

A database is a structure that comes in two flavors: a flat database and a relational database. A relational database is much more oriented to the human mind and is often preferred over the gabble-de-gook flat database that are just stored on hard drives like a text file. MySQL is a relational database.

In a relational structured database there are tables that store data. The columns define which kinds of information will be stored in the table. An individual column must be created for each type of data you wish to store (i.e. Age, Weight, Height).

On the other hand, a row contains the actual values for these specified columns. Each row will have 1 value for each and every column. For example a table with columns (Name, Age, Weight-lbs) could have a row with the values (Bob, 65, 165). If all this relational database talk is too confusing, don’t despair. We will talk about and show a few examples in the coming lessons.

Mysql-Creating a Derived Data Column

Thursday, July 24th, 2008

Frequently we query our database for a value but then have to always do the same manipulation on it before we can use it. Well it can often be useful to do this “once” in the database and then store the manipulated value in a separate column of the database.

Here is a very simple example
INSERT INTO tbl_name (col1,col2) VALUES(15,col1*3.14159);

Where col2 is set to the value of col1*pi

You could also do more complex calculation/filtering/shortening in your code eg php,ASP etc

Web Designing-Don’t redeclare inherited values

Wednesday, July 16th, 2008

The values of many properties are inherited by any descendants of the element that you specify the property for. color and the font related properties are the most common examples of such properties.

Be aware that some properties may be overridden by browser specific user agent style sheets, i.e. the browser’s defaults. That’s why you can’t make all headings non bold with the following rule:

1. body { font-weight:normal; }

The browser’s predefined rules are more specific because of the cascade, which is described next.

Php:Variable variables

Tuesday, July 1st, 2008

A variable variable looks like this: $$var

So, if $var = ‘foo’ and $foo = ‘bar’ then $$var would contain the value ‘bar’ because $$var can be
thought of as $’foo’ which is simply $foo which has the value ‘bar’.

Variable variables sound like a cryptic a useless concept, but they can be useful sometimes. For
example, if we have a configuration file consisting of configuration directives and values in this
format:

foo=bar
abc=123
Then it is very easy to read this file and create corresponding variables:

<?php
$fp = fopen(’config.txt’,'r’);
while(true) {
$line = fgets($fp,80);
if(!feof($fp)) {
if($line[0]==’#’ || strlen($line)<2) continue;
list($name,$val)=explode(’=',$line,2);
$$name=trim($val);
} else break;
}
fclose($fp);
?>
Along the same lines as variable variables, you can create compound variables and variable
functions.

<?php
$str = ‘var’;
$var_toaster = “Hello World”;
echo ${$str.’_toaster’};
$str(); // Calls a function named var()
${$str.’_abc’}(); // Calls a function named var_abc()
?>

PHP:Arrange an array by the first letter

Monday, June 30th, 2008

Here is a small PHP tips&tricks post : we have an array full of values, let’s say a country list (in this example the list is limited, we don’t want to see 190+ values).
PHP  CODE:

Array
(
[0] => Array
(
[0] => Afghanistan
[name] => Afghanistan
[1] => AF
[code] => AF
)

[1] => Array
(
[0] => Albania
[name] => Albania
[1] => AL
[code] => AL
)

[2] => Array
(
[0] => Algeria
[name] => Algeria
[1] => DZ
[code] => DZ
)

[3] => Array
(
[0] => Bangladesh
[name] => Bangladesh
[1] => BD
[code] => BD
)

[4] => Array
(
[0] => Barbados
[name] => Barbados
[1] => BB
[code] => BB
)

[5] => Array
(
[0] => Belgium
[name] => Belgium
[1] => BE
[code] => BE
)

[6] => Array
(
[0] => Brazil
[name] => Brazil
[1] => BR
[code] => BR
)

[7] => Array
(
[0] => Cape Verde
[name] => Cape Verde
[1] => CV
[code] => CV
)

[8] => Array
(
[0] => Cayman Islands
[name] => Cayman Islands
[1] => KY
[code] => KY
)
)

PHP CODE:

Array

(

[0] => Array

(

[0] => Afghanistan

[name] => Afghanistan

[1] => AF

[code] => AF

)

[1] => Array

(

[0] => Albania
[name] => Albania

[1] => AL

[code] => AL

)

[2] => Array

(

[0] => Algeria

[name] => Algeria

[1] => DZ

[code] => DZ

)

[3] => Array

(

[0] => Bangladesh

[name] => Bangladesh

[1] => BD

[code] => BD

)

[4] => Array

(

[0] => Barbados

[name] => Barbados

[1] => BB
[code] => BB

)

[5] => Array

(

[0] => Belgium

[name] => Belgium

[1] => BE

[code] => BE

)

[6] => Array

(

[0] => Brazil

[name] => Brazil

[1] => BR

[code] => BR

)

[7] => Array

(

[0] => Cape Verde

[name] => Cape Verde

[1] => CV

[code] => CV

)

[8] => Array

(

[0] => Cayman Islands

[name] => Cayman Islands

[1] => KY

[code] => KY

)

)

and we want to display like this
-A-

* Afghanistan
* Albania
* Algeria

-B-

* Bangladesh
* Barbados
* Belgium
* Brazil

-C-

* Cape Verde
* Cayman Islands

, the right and easy way to do this would be to retain in a variable the first letter of the last country and in another variable the first letter of the current country. We compare them and if they are different we just output the first letter and then the name of the current country. All this in just few and simple to understand lines, right? :P
PHP  CODE:

//try to do the A-Z list
$v = function to get your country list from a DB sorted by country name!;
$last_letter = ”;
$current_letter = ”;
for ($i=0;$i
” . $current_letter . ”

“;
}
print $v[$i]["name"] . “”;
$last_letter = $current_letter;
}

PHP CODE:

//try to do the A-Z list

$v = function to get your country list from a DB sorted by country name!;

$last_letter = ”;

$current_letter = ”;

for ($i=0;$i<count($v);$i++)

{

$current_letter = substr($v[$i]["name"],0,1);

if ($last_letter != $current_letter)

{

print “<div align=center>” . $current_letter . “</div>”;

}

print $v[$i]["name"] . “<br />”;

$last_letter = $current_letter;

}

how to remove empty element from array

Monday, June 30th, 2008

$cleaned_array = array_filter($countries);
by not supplying a callback function to array_filter function it skips the empty values

PHP:Change/modify configuration values for ‘include_path’ in php ini configuration runtime

Monday, June 30th, 2008

ini_set(’include_path’, ‘/usr/share/code’ . PATH_SEPARATOR . ini_get(’include_path’));