To access a twitter rss feed the url is now
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=xxxxx
where xxxxx is the twitter login name
It took me ages to find as Twitter no longer advertises rss feeds and I will probably forget it later so it is here for posterity and anyone else who may be looking for it.
Chandrika Gauranga (aka Clare Ross) is me. This blog started as a simple diary of a journey to Jagannath Puri, India...
Friday, January 20, 2012
Saturday, January 07, 2012
Srila Bhaktikumuda Santa Goswami Maharaja
Srila Bhaktikumuda Santa Goswami Maharaja, the last remaining disciple of Srila Bhaktisidhanta Saraswati Thakura Prabhupada left this world today at 1am. The well known founder of the Krishna Consciousness Movement, A.C Bhaktivedanta Swami Prabhupada, was also a disciple of Srila Bhaktisidhanta Saraswati Thakura Prabhupada, one of his God Brothers. He is one in a line of disciplic succession of Gaudiya Vaishnavas, that will be continued by his own disciples and beyond.
Nityananda Gauranga
Thursday, January 05, 2012
PHP - Parsing a csv file created by Excel
Useful for updating tabular data on a website, without editing any html. Especially if there is no access to a database to upload the info. I found this function at php.net. It returns an array with all the data in the csv file...
function parse_csv($file,$comma=',',$quote='"',$newline="\n") {
$db_quote = $quote . $quote;
// Clean up file
$file = trim($file);
$file = str_replace("\r\n",$newline,$file);
$file = str_replace($db_quote,'"',$file); // replace double quotes with " HTML entities
$file = str_replace(',",',',,',$file); // handle ,"", empty cells correctly
$file .= $comma; // Put a comma on the end, so we parse last cell
$inquotes = false;
$start_point = 0;
$row = 0;
for($i=0; $i<strlen($file); $i++) {
$char = $file[$i];
if ($char == $quote) {
if ($inquotes) {
$inquotes = false;
}
else {
$inquotes = true;
}
}
if (($char == $comma or $char == $newline) and !$inquotes) {
$cell = substr($file,$start_point,$i-$start_point);
$cell = str_replace($quote,'',$cell); // Remove delimiter quotes
$cell = str_replace('"',$quote,$cell); // Add in data quotes
$data[$row][] = $cell;
$start_point = $i + 1;
if ($char == $newline) {
$row ++;
}
}
}
return $data;
}
$filename = "/path/to/file.csv";
$fd = fopen ($filename, "r");
$file = fread ($fd,filesize ($filename));
$new_array=parse_csv($file); // Returns an array of data from the csv file
Then the array can be used the same way a returned mysql result set would be used (see here). The array can be searched (see previous post here) or to simply access elements from the returned array you can simply call individual elements as such...
//line 1 data
echo $new_array[0][0];
echo $new_array[0][1];
echo $new_array[0][2];
//etc
//line 2 data
echo $new_array[1][0];
echo $new_array[1][1];
echo $new_array[1][2];
//etc
To pick out random lines from a csv (eg.with 3 columns year,day,month) and use that data the rand function can be used as follows...
$num=count($new_array);
$num=$num-1;//minus one to cope with 0 in array
$i=rand (0, $num );
$year=$new_array[$i][0];
$day=$new_array[$i][1];
$month=$new_array[$i][2];
echo "The random year is ".$year.". The random day is ".$day.". The random month is ".$month;
function parse_csv($file,$comma=',',$quote='"',$newline="\n") {
$db_quote = $quote . $quote;
// Clean up file
$file = trim($file);
$file = str_replace("\r\n",$newline,$file);
$file = str_replace($db_quote,'"',$file); // replace double quotes with " HTML entities
$file = str_replace(',",',',,',$file); // handle ,"", empty cells correctly
$file .= $comma; // Put a comma on the end, so we parse last cell
$inquotes = false;
$start_point = 0;
$row = 0;
for($i=0; $i<strlen($file); $i++) {
$char = $file[$i];
if ($char == $quote) {
if ($inquotes) {
$inquotes = false;
}
else {
$inquotes = true;
}
}
if (($char == $comma or $char == $newline) and !$inquotes) {
$cell = substr($file,$start_point,$i-$start_point);
$cell = str_replace($quote,'',$cell); // Remove delimiter quotes
$cell = str_replace('"',$quote,$cell); // Add in data quotes
$data[$row][] = $cell;
$start_point = $i + 1;
if ($char == $newline) {
$row ++;
}
}
}
return $data;
}
$filename = "/path/to/file.csv";
$fd = fopen ($filename, "r");
$file = fread ($fd,filesize ($filename));
$new_array=parse_csv($file); // Returns an array of data from the csv file
Then the array can be used the same way a returned mysql result set would be used (see here). The array can be searched (see previous post here) or to simply access elements from the returned array you can simply call individual elements as such...
//line 1 data
echo $new_array[0][0];
echo $new_array[0][1];
echo $new_array[0][2];
//etc
//line 2 data
echo $new_array[1][0];
echo $new_array[1][1];
echo $new_array[1][2];
//etc
To pick out random lines from a csv (eg.with 3 columns year,day,month) and use that data the rand function can be used as follows...
$num=count($new_array);
$num=$num-1;//minus one to cope with 0 in array
$i=rand (0, $num );
$year=$new_array[$i][0];
$day=$new_array[$i][1];
$month=$new_array[$i][2];
echo "The random year is ".$year.". The random day is ".$day.". The random month is ".$month;
Thursday, December 01, 2011
Gwalior Childrens Charity Award For Volunteering
I manage the website for the GCC at http://www.helpchildrenofindia.org . This is a picture of me receiving an award from Dr B.K.Sharma. He and his late wife Meena are founders of the charity that has rescued many destitute
children from various state run institutions. When his wife passed, her estate was used to build a home, hospital and school in Gwalior, Madhya Pradesh (one of the poorest and most deprived parts of India) The charity provides for the residents there and is working to become self sufficient with solar power, a Goshala, and farming area. As well as helping the disabled and destitute, the place also helps local people, especially girls from surrounding villages, providing them with a free education at the new school that opened this year. They also provide a mobile medical center that travels offering medical assistance in the surrounding area.
children from various state run institutions. When his wife passed, her estate was used to build a home, hospital and school in Gwalior, Madhya Pradesh (one of the poorest and most deprived parts of India) The charity provides for the residents there and is working to become self sufficient with solar power, a Goshala, and farming area. As well as helping the disabled and destitute, the place also helps local people, especially girls from surrounding villages, providing them with a free education at the new school that opened this year. They also provide a mobile medical center that travels offering medical assistance in the surrounding area.
Wednesday, October 26, 2011
Currency database - csv with currency symbol html codes
I couldnt find a currencies data file anywhere to import into a database. I wanted the currency name, abbreviation and the html code for the currency symbol, to use in select menus and such.
So I made a csv using the data from XE.com. That took a little time using regex to find and replace the table data and as it took a little time I thought I would share the file here for anyone else who may need currency data with html symbols for website use.
This is the csv data that can be copied and pasted into a file to import into a database table..
Albania Lek--ALL--Lek | Afghanistan Afghani--AFN--؋ | Argentina Peso--ARS--$ | Aruba Guilder--AWG--ƒ | Australia Dollar--AUD--$ | Azerbaijan New Manat--AZN--ман | Bahamas Dollar--BSD--$ | Barbados Dollar--BBD--$ | Belarus Ruble--BYR--p. | Belize Dollar--BZD--BZ$ | Bermuda Dollar--BMD--$ | Bolivia Boliviano--BOB--$b | Bosnia and Herzegovina Convertible Marka--BAM--KM | Botswana Pula--BWP--P | Bulgaria Lev--BGN--лв | Brazil Real--BRL--R$ | Brunei Darussalam Dollar--BND--$ | Cambodia Riel--KHR--៛ | Canada Dollar--CAD--$ | Cayman Islands Dollar--KYD--$ | Chile Peso--CLP--$ | China Yuan Renminbi--CNY--¥ | Colombia Peso--COP--$ | Costa Rica Colon--CRC--₡ | Croatia Kuna--HRK--kn | Cuba Peso--CUP--₱ | Czech Republic Koruna--CZK--Kč | Denmark Krone--DKK--kr | Dominican Republic Peso--DOP--RD$ | East Caribbean Dollar--XCD--$ | Egypt Pound--EGP--£ | El Salvador Colon--SVC--$ | Estonia Kroon--EEK--kr | Euro Member Countries--EUR--€ | Falkland Islands (Malvinas) Pound--FKP--£ | Fiji Dollar--FJD--$ | Ghana Cedis--GHC--¢ | Gibraltar Pound--GIP--£ | Guatemala Quetzal--GTQ--Q | Guernsey Pound--GGP--£ | Guyana Dollar--GYD--$ | Honduras Lempira--HNL--L | Hong Kong Dollar--HKD--$ | Hungary Forint--HUF--Ft | Iceland Krona--ISK--kr | India Rupee--INR--₹ | Indonesia Rupiah--IDR--Rp | Iran Rial--IRR--﷼ | Isle of Man Pound--IMP--£ | Israel Shekel--ILS--₪ | Jamaica Dollar--JMD--J$ | Japan Yen--JPY--¥ | Jersey Pound--JEP--£ | Kazakhstan Tenge--KZT--лв | Korea (North) Won--KPW--₩ | Korea (South) Won--KRW--₩ | Kyrgyzstan Som--KGS--лв | Laos Kip--LAK--₭ | Latvia Lat--LVL--Ls | Lebanon Pound--LBP--£ | Liberia Dollar--LRD--$ | Lithuania Litas--LTL--Lt | Macedonia Denar--MKD--ден | Malaysia Ringgit--MYR--RM | Mauritius Rupee--MUR--₨ | Mexico Peso--MXN--$ | Mongolia Tughrik--MNT--₮ | Mozambique Metical--MZN--MT | Namibia Dollar--NAD--$ | Nepal Rupee--NPR--₨ | Netherlands Antilles Guilder--ANG--ƒ | New Zealand Dollar--NZD--$ | Nicaragua Cordoba--NIO--C$ | Nigeria Naira--NGN--₦ | Korea (North) Won--KPW--₩ | Norway Krone--NOK--kr | Oman Rial--OMR--﷼ | Pakistan Rupee--PKR--₨ | Panama Balboa--PAB--B/. | Paraguay Guarani--PYG--Gs | Peru Nuevo Sol--PEN--S/. | Philippines Peso--PHP--₱ | Poland Zloty--PLN--zł | Qatar Riyal--QAR--﷼ | Romania New Leu--RON--lei | Russia Ruble--RUB--руб | Saint Helena Pound--SHP--£ | Saudi Arabia Riyal--SAR--﷼ | Serbia Dinar--RSD--Дин. | Seychelles Rupee--SCR--₨ | Singapore Dollar--SGD--$ | Solomon Islands Dollar--SBD--$ | Somalia Shilling--SOS--S | South Africa Rand--ZAR--R | Korea (South) Won--KRW--₩ | Sri Lanka Rupee--LKR--₨ | Sweden Krona--SEK--kr | Switzerland Franc--CHF--CHF | Suriname Dollar--SRD--$ | Syria Pound--SYP--£ | Taiwan New Dollar--TWD--NT$ | Thailand Baht--THB--฿ | Trinidad and Tobago Dollar--TTD--TT$ | Turkey Lira--TRY--TL | Turkey Lira--TRL--₤ | Tuvalu Dollar--TVD--$ | Ukraine Hryvna--UAH--₴ | United Kingdom Pound--GBP--£ | United States Dollar--USD--$ | Uruguay Peso--UYU--$U | Uzbekistan Som--UZS--лв | Venezuela Bolivar Fuerte--VEF--Bs | Viet Nam Dong--VND--₫ | Yemen Rial--YER--﷼ | Zimbabwe Dollar--ZWD--Z$
I created a mysql table with 4 columns, id,name,abb,html and then loaded the above data in phpmyadmin using the following mysql
This is the currency data that is contained, and how the html codes display...
Albania Lek - ALL - Lek
Afghanistan Afghani - AFN - ؋
Argentina Peso - ARS - $
Aruba Guilder - AWG - ƒ
Australia Dollar - AUD - $
Azerbaijan New Manat - AZN - ман
Bahamas Dollar - BSD - $
Barbados Dollar - BBD - $
Belarus Ruble - BYR - p.
Belize Dollar - BZD - BZ$
Bermuda Dollar - BMD - $
Bolivia Boliviano - BOB - $b
Bosnia and Herzegovina Convertible Marka - BAM - KM
Botswana Pula - BWP - P
Bulgaria Lev - BGN - лв
Brazil Real - BRL - R$
Brunei Darussalam Dollar - BND - $
Cambodia Riel - KHR - ៛
Canada Dollar - CAD - $
Cayman Islands Dollar - KYD - $
Chile Peso - CLP - $
China Yuan Renminbi - CNY - ¥
Colombia Peso - COP - $
Costa Rica Colon - CRC - ₡
Croatia Kuna - HRK - kn
Cuba Peso - CUP - ₱
Czech Republic Koruna - CZK - Kč
Denmark Krone - DKK - kr
Dominican Republic Peso - DOP - RD$
East Caribbean Dollar - XCD - $
Egypt Pound - EGP - £
El Salvador Colon - SVC - $
Estonia Kroon - EEK - kr
Euro Member Countries - EUR - €
Falkland Islands (Malvinas) Pound - FKP - £
Fiji Dollar - FJD - $
Ghana Cedis - GHC - ¢
Gibraltar Pound - GIP - £
Guatemala Quetzal - GTQ - Q
Guernsey Pound - GGP - £
Guyana Dollar - GYD - $
Honduras Lempira - HNL - L
Hong Kong Dollar - HKD - $
Hungary Forint - HUF - Ft
Iceland Krona - ISK - kr
India Rupee - INR - ₹
Indonesia Rupiah - IDR - Rp
Iran Rial - IRR - ﷼
Isle of Man Pound - IMP - £
Israel Shekel - ILS - ₪
Jamaica Dollar - JMD - J$
Japan Yen - JPY - ¥
Jersey Pound - JEP - £
Kazakhstan Tenge - KZT - лв
Korea (North) Won - KPW - ₩
Korea (South) Won - KRW - ₩
Kyrgyzstan Som - KGS - лв
Laos Kip - LAK - ₭
Latvia Lat - LVL - Ls
Lebanon Pound - LBP - £
Liberia Dollar - LRD - $
Lithuania Litas - LTL - Lt
Macedonia Denar - MKD - ден
Malaysia Ringgit - MYR - RM
Mauritius Rupee - MUR - ₨
Mexico Peso - MXN - $
Mongolia Tughrik - MNT - ₮
Mozambique Metical - MZN - MT
Namibia Dollar - NAD - $
Nepal Rupee - NPR - ₨
Netherlands Antilles Guilder - ANG - ƒ
New Zealand Dollar - NZD - $
Nicaragua Cordoba - NIO - C$
Nigeria Naira - NGN - ₦
Korea (North) Won - KPW - ₩
Norway Krone - NOK - kr
Oman Rial - OMR - ﷼
Pakistan Rupee - PKR - ₨
Panama Balboa - PAB - B/.
Paraguay Guarani - PYG - Gs
Peru Nuevo Sol - PEN - S/.
Philippines Peso - PHP - ₱
Poland Zloty - PLN - zł
Qatar Riyal - QAR - ﷼
Romania New Leu - RON - lei
Russia Ruble - RUB - руб
Saint Helena Pound - SHP - £
Saudi Arabia Riyal - SAR - ﷼
Serbia Dinar - RSD - Дин.
Seychelles Rupee - SCR - ₨
Singapore Dollar - SGD - $
Solomon Islands Dollar - SBD - $
Somalia Shilling - SOS - S
South Africa Rand - ZAR - R
Korea (South) Won - KRW - ₩
Sri Lanka Rupee - LKR - ₨
Sweden Krona - SEK - kr
Switzerland Franc - CHF - CHF
Suriname Dollar - SRD - $
Syria Pound - SYP - £
Taiwan New Dollar - TWD - NT$
Thailand Baht - THB - ฿
Trinidad and Tobago Dollar - TTD - TT$
Turkey Lira - TRY - TL
Turkey Lira - TRL - ₤
Tuvalu Dollar - TVD - $
Ukraine Hryvna - UAH - ₴
United Kingdom Pound - GBP - £
United States Dollar - USD - $
Uruguay Peso - UYU - $U
Uzbekistan Som - UZS - лв
Venezuela Bolivar Fuerte - VEF - Bs
Viet Nam Dong - VND - ₫
Yemen Rial - YER - ﷼
Zimbabwe Dollar - ZWD - Z$
So I made a csv using the data from XE.com. That took a little time using regex to find and replace the table data and as it took a little time I thought I would share the file here for anyone else who may need currency data with html symbols for website use.
This is the csv data that can be copied and pasted into a file to import into a database table..
Albania Lek--ALL--Lek | Afghanistan Afghani--AFN--؋ | Argentina Peso--ARS--$ | Aruba Guilder--AWG--ƒ | Australia Dollar--AUD--$ | Azerbaijan New Manat--AZN--ман | Bahamas Dollar--BSD--$ | Barbados Dollar--BBD--$ | Belarus Ruble--BYR--p. | Belize Dollar--BZD--BZ$ | Bermuda Dollar--BMD--$ | Bolivia Boliviano--BOB--$b | Bosnia and Herzegovina Convertible Marka--BAM--KM | Botswana Pula--BWP--P | Bulgaria Lev--BGN--лв | Brazil Real--BRL--R$ | Brunei Darussalam Dollar--BND--$ | Cambodia Riel--KHR--៛ | Canada Dollar--CAD--$ | Cayman Islands Dollar--KYD--$ | Chile Peso--CLP--$ | China Yuan Renminbi--CNY--¥ | Colombia Peso--COP--$ | Costa Rica Colon--CRC--₡ | Croatia Kuna--HRK--kn | Cuba Peso--CUP--₱ | Czech Republic Koruna--CZK--Kč | Denmark Krone--DKK--kr | Dominican Republic Peso--DOP--RD$ | East Caribbean Dollar--XCD--$ | Egypt Pound--EGP--£ | El Salvador Colon--SVC--$ | Estonia Kroon--EEK--kr | Euro Member Countries--EUR--€ | Falkland Islands (Malvinas) Pound--FKP--£ | Fiji Dollar--FJD--$ | Ghana Cedis--GHC--¢ | Gibraltar Pound--GIP--£ | Guatemala Quetzal--GTQ--Q | Guernsey Pound--GGP--£ | Guyana Dollar--GYD--$ | Honduras Lempira--HNL--L | Hong Kong Dollar--HKD--$ | Hungary Forint--HUF--Ft | Iceland Krona--ISK--kr | India Rupee--INR--₹ | Indonesia Rupiah--IDR--Rp | Iran Rial--IRR--﷼ | Isle of Man Pound--IMP--£ | Israel Shekel--ILS--₪ | Jamaica Dollar--JMD--J$ | Japan Yen--JPY--¥ | Jersey Pound--JEP--£ | Kazakhstan Tenge--KZT--лв | Korea (North) Won--KPW--₩ | Korea (South) Won--KRW--₩ | Kyrgyzstan Som--KGS--лв | Laos Kip--LAK--₭ | Latvia Lat--LVL--Ls | Lebanon Pound--LBP--£ | Liberia Dollar--LRD--$ | Lithuania Litas--LTL--Lt | Macedonia Denar--MKD--ден | Malaysia Ringgit--MYR--RM | Mauritius Rupee--MUR--₨ | Mexico Peso--MXN--$ | Mongolia Tughrik--MNT--₮ | Mozambique Metical--MZN--MT | Namibia Dollar--NAD--$ | Nepal Rupee--NPR--₨ | Netherlands Antilles Guilder--ANG--ƒ | New Zealand Dollar--NZD--$ | Nicaragua Cordoba--NIO--C$ | Nigeria Naira--NGN--₦ | Korea (North) Won--KPW--₩ | Norway Krone--NOK--kr | Oman Rial--OMR--﷼ | Pakistan Rupee--PKR--₨ | Panama Balboa--PAB--B/. | Paraguay Guarani--PYG--Gs | Peru Nuevo Sol--PEN--S/. | Philippines Peso--PHP--₱ | Poland Zloty--PLN--zł | Qatar Riyal--QAR--﷼ | Romania New Leu--RON--lei | Russia Ruble--RUB--руб | Saint Helena Pound--SHP--£ | Saudi Arabia Riyal--SAR--﷼ | Serbia Dinar--RSD--Дин. | Seychelles Rupee--SCR--₨ | Singapore Dollar--SGD--$ | Solomon Islands Dollar--SBD--$ | Somalia Shilling--SOS--S | South Africa Rand--ZAR--R | Korea (South) Won--KRW--₩ | Sri Lanka Rupee--LKR--₨ | Sweden Krona--SEK--kr | Switzerland Franc--CHF--CHF | Suriname Dollar--SRD--$ | Syria Pound--SYP--£ | Taiwan New Dollar--TWD--NT$ | Thailand Baht--THB--฿ | Trinidad and Tobago Dollar--TTD--TT$ | Turkey Lira--TRY--TL | Turkey Lira--TRL--₤ | Tuvalu Dollar--TVD--$ | Ukraine Hryvna--UAH--₴ | United Kingdom Pound--GBP--£ | United States Dollar--USD--$ | Uruguay Peso--UYU--$U | Uzbekistan Som--UZS--лв | Venezuela Bolivar Fuerte--VEF--Bs | Viet Nam Dong--VND--₫ | Yemen Rial--YER--﷼ | Zimbabwe Dollar--ZWD--Z$
I created a mysql table with 4 columns, id,name,abb,html and then loaded the above data in phpmyadmin using the following mysql
LOAD DATA LOCAL INFILE '/path/to/currencies/file.txt' INTO TABLE `currency` FIELDS TERMINATED BY '--' ESCAPED BY '\\' LINES TERMINATED BY ' | '(
`name` , `abb` , `html`
)
This is the currency data that is contained, and how the html codes display...
Albania Lek - ALL - Lek
Afghanistan Afghani - AFN - ؋
Argentina Peso - ARS - $
Aruba Guilder - AWG - ƒ
Australia Dollar - AUD - $
Azerbaijan New Manat - AZN - ман
Bahamas Dollar - BSD - $
Barbados Dollar - BBD - $
Belarus Ruble - BYR - p.
Belize Dollar - BZD - BZ$
Bermuda Dollar - BMD - $
Bolivia Boliviano - BOB - $b
Bosnia and Herzegovina Convertible Marka - BAM - KM
Botswana Pula - BWP - P
Bulgaria Lev - BGN - лв
Brazil Real - BRL - R$
Brunei Darussalam Dollar - BND - $
Cambodia Riel - KHR - ៛
Canada Dollar - CAD - $
Cayman Islands Dollar - KYD - $
Chile Peso - CLP - $
China Yuan Renminbi - CNY - ¥
Colombia Peso - COP - $
Costa Rica Colon - CRC - ₡
Croatia Kuna - HRK - kn
Cuba Peso - CUP - ₱
Czech Republic Koruna - CZK - Kč
Denmark Krone - DKK - kr
Dominican Republic Peso - DOP - RD$
East Caribbean Dollar - XCD - $
Egypt Pound - EGP - £
El Salvador Colon - SVC - $
Estonia Kroon - EEK - kr
Euro Member Countries - EUR - €
Falkland Islands (Malvinas) Pound - FKP - £
Fiji Dollar - FJD - $
Ghana Cedis - GHC - ¢
Gibraltar Pound - GIP - £
Guatemala Quetzal - GTQ - Q
Guernsey Pound - GGP - £
Guyana Dollar - GYD - $
Honduras Lempira - HNL - L
Hong Kong Dollar - HKD - $
Hungary Forint - HUF - Ft
Iceland Krona - ISK - kr
India Rupee - INR - ₹
Indonesia Rupiah - IDR - Rp
Iran Rial - IRR - ﷼
Isle of Man Pound - IMP - £
Israel Shekel - ILS - ₪
Jamaica Dollar - JMD - J$
Japan Yen - JPY - ¥
Jersey Pound - JEP - £
Kazakhstan Tenge - KZT - лв
Korea (North) Won - KPW - ₩
Korea (South) Won - KRW - ₩
Kyrgyzstan Som - KGS - лв
Laos Kip - LAK - ₭
Latvia Lat - LVL - Ls
Lebanon Pound - LBP - £
Liberia Dollar - LRD - $
Lithuania Litas - LTL - Lt
Macedonia Denar - MKD - ден
Malaysia Ringgit - MYR - RM
Mauritius Rupee - MUR - ₨
Mexico Peso - MXN - $
Mongolia Tughrik - MNT - ₮
Mozambique Metical - MZN - MT
Namibia Dollar - NAD - $
Nepal Rupee - NPR - ₨
Netherlands Antilles Guilder - ANG - ƒ
New Zealand Dollar - NZD - $
Nicaragua Cordoba - NIO - C$
Nigeria Naira - NGN - ₦
Korea (North) Won - KPW - ₩
Norway Krone - NOK - kr
Oman Rial - OMR - ﷼
Pakistan Rupee - PKR - ₨
Panama Balboa - PAB - B/.
Paraguay Guarani - PYG - Gs
Peru Nuevo Sol - PEN - S/.
Philippines Peso - PHP - ₱
Poland Zloty - PLN - zł
Qatar Riyal - QAR - ﷼
Romania New Leu - RON - lei
Russia Ruble - RUB - руб
Saint Helena Pound - SHP - £
Saudi Arabia Riyal - SAR - ﷼
Serbia Dinar - RSD - Дин.
Seychelles Rupee - SCR - ₨
Singapore Dollar - SGD - $
Solomon Islands Dollar - SBD - $
Somalia Shilling - SOS - S
South Africa Rand - ZAR - R
Korea (South) Won - KRW - ₩
Sri Lanka Rupee - LKR - ₨
Sweden Krona - SEK - kr
Switzerland Franc - CHF - CHF
Suriname Dollar - SRD - $
Syria Pound - SYP - £
Taiwan New Dollar - TWD - NT$
Thailand Baht - THB - ฿
Trinidad and Tobago Dollar - TTD - TT$
Turkey Lira - TRY - TL
Turkey Lira - TRL - ₤
Tuvalu Dollar - TVD - $
Ukraine Hryvna - UAH - ₴
United Kingdom Pound - GBP - £
United States Dollar - USD - $
Uruguay Peso - UYU - $U
Uzbekistan Som - UZS - лв
Venezuela Bolivar Fuerte - VEF - Bs
Viet Nam Dong - VND - ₫
Yemen Rial - YER - ﷼
Zimbabwe Dollar - ZWD - Z$
Monday, October 24, 2011
PHP - function to search an associative array
To find the value of part of an associative array such as the one below, the function below will search for a term within the key that is specified in the function...
$arr = "Array ( [0] => Array ( [id] => 1 [date] => 2011-10-18 [details] => Shopping ) [1] => Array ( [id] => 2 [date] => 2011-10-01 [details] => Tax ) [2] => Array ( [id] => 123 [date] => 2011-10-18 [details] => Petrol )";
function getKeys($arr,$search){
foreach($arr as $keys=>$values)
{
foreach ($values as $key => $value) {
if($key=="date" && $value==$search){//$key=="date" can be any key from the array
$getkeys.=$keys.",";
}
}
}
$len=strlen($getkeys)-1; //get the length of $getkeys
$getkeys=substr($getkeys,0,$len); //remove the last comma
$getkeys=$pieces = explode(",", $getkeys); //make an arrayof the keys
return $getkeys;
}//end function getKeys
$getkeys=getKeys($arr,"2011-10-18");//search term can be anything, here it is a date
print_r($getkeys);//print the array
This will return an array of the keys of the elements of the array in which the search term was found. In this case Array ( [0] => 0 [1] => 2 )
$arr = "Array ( [0] => Array ( [id] => 1 [date] => 2011-10-18 [details] => Shopping ) [1] => Array ( [id] => 2 [date] => 2011-10-01 [details] => Tax ) [2] => Array ( [id] => 123 [date] => 2011-10-18 [details] => Petrol )";
function getKeys($arr,$search){
foreach($arr as $keys=>$values)
{
foreach ($values as $key => $value) {
if($key=="date" && $value==$search){//$key=="date" can be any key from the array
$getkeys.=$keys.",";
}
}
}
$len=strlen($getkeys)-1; //get the length of $getkeys
$getkeys=substr($getkeys,0,$len); //remove the last comma
$getkeys=$pieces = explode(",", $getkeys); //make an arrayof the keys
return $getkeys;
}//end function getKeys
$getkeys=getKeys($arr,"2011-10-18");//search term can be anything, here it is a date
print_r($getkeys);//print the array
This will return an array of the keys of the elements of the array in which the search term was found. In this case Array ( [0] => 0 [1] => 2 )
Monday, October 17, 2011
MySQL resultset as an associative array
To save time and resources, when a php application is going to require the same resultset often, the resultset can be saved in a session as an associative array. Then when required in the script the saved session data can be referenced instead of querying the database again.
To return a resultset as an array named $ac_arr requires the following mysql...
$result=mysql_query("SELECT name,startdate,enddate FROM accounts") or die(mysql_error());
while(($ac_arr[] = mysql_fetch_assoc($result)) || array_pop($ac_arr));
The array_pop() function simply removes the extra element that would otherwise be appended to the array.
This can then be stored in a session variable and later referenced without re-querying the database...
$_SESSION['ac_array']=$ac_arr;
To list the keys and values of elements in the array
<?php
$acs=$_SESSION['ac_array'];
foreach($acs as $keys=>$values)
{
foreach ($values as $key => $value) {
echo $keys." : ".$key.":".$value."<br />";
}
}
?>
The above will display a list like this
0 : name : AC1
0 : startdate : 2011-08-16
0 : enddate : 2011-12-16
1 : name : AC2
1 : startdate : 2014-07-25
1 : enddate : 2024-07-25
2 : name : AC3
2 : startdate : 2012-05-10
2 : enddate : 2022-05-10
so you can reference any element in the array by calling
$acs[0][name] (will return AC1)
$acs[2][startdate] (will return 2012-05-10)
To return a resultset as an array named $ac_arr requires the following mysql...
$result=mysql_query("SELECT name,startdate,enddate FROM accounts") or die(mysql_error());
while(($ac_arr[] = mysql_fetch_assoc($result)) || array_pop($ac_arr));
The array_pop() function simply removes the extra element that would otherwise be appended to the array.
This can then be stored in a session variable and later referenced without re-querying the database...
$_SESSION['ac_array']=$ac_arr;
To list the keys and values of elements in the array
<?php
$acs=$_SESSION['ac_array'];
foreach($acs as $keys=>$values)
{
foreach ($values as $key => $value) {
echo $keys." : ".$key.":".$value."<br />";
}
}
?>
The above will display a list like this
0 : name : AC1
0 : startdate : 2011-08-16
0 : enddate : 2011-12-16
1 : name : AC2
1 : startdate : 2014-07-25
1 : enddate : 2024-07-25
2 : name : AC3
2 : startdate : 2012-05-10
2 : enddate : 2022-05-10
so you can reference any element in the array by calling
$acs[0][name] (will return AC1)
$acs[2][startdate] (will return 2012-05-10)
Sunday, October 16, 2011
Amino Acids In protein - Complementary protein sources
When eating a vegetarian diet, it is important to get the protein right.
Usually the protein content of various food is labelled in grams, but not all protein is equal. The combination of amino acids that make up the protein does matter.
For example, a person could get (for example) 10g protein from 100g wholewheat bread. However the human body would be unable to utilise all that protein, as wheat protein does not contain all the essential amino acids (the amino acids that the body has to be fed, as it can not make them itself). A food that contains all the essential amino acids is called a "complete protein". Vegetarian sources are dairy products, quinoa, soya. A food that contains protein but not all the essential amino acids is called an incomplete protein. An incomplete protein has some amino acids that limit it, these are called "limiting amino acids". In wheat (and most grain) protein for example, the limiting amino acid is lysine. As the body uses amino acids together to do stuff, in a ratio, it can therefor only process as much protein as the limiting amino acid allows.
So that is why it is necessary to complement vegetarian protein sources sometimes. For example mixing wheat or rice protein, with a legume protein (rice and dal, beans on toast, tortilla and refreid beans), results in all essential amino acids being present. As although wheat and rice lack lysine,it has plenty of methionine and tryptophan. Legumes are high in lysine, but low in methionine and tryptophan. Together they form a complementary protein.
I found a good utility online to check the amino acid profile of foods (from the USDA database)
Amino Acid Check
This can help to choose a variety of foods over a course of a day that will complement each other, so providing enough of all the essential amino acids.
I was surprised to see that most green vegetables, spinach, broccoli etc, in fact have excellent amino acid profiles, with all the essential amino acids contained. Obviously you would have to eat alot of greens to get the rda of protein, but I have read that our ancestors, in paleolithic times, might have eaten several carrier bag fulls of green leafy veg a day.
An interesting fact for weight watchers, is that 600g of broccoli, contains nearly 20g protein and under 150 calories. Weight watchers usually like to eat food that keeps them nice and full up without having too many cals. The equivalent calorie amount of rice, would be just around 35g, and would only provide about 3g protein. If hungry, I know which choice i would go for to keep me full for longer!
As a side note, recent reports state that eating broccoli along with something spicy such as mustard or horseradish, boosts it anto cancer properties. Vegetables have so many wonderful properties, that are only just being discovered.
I once used the USDA database to analyse my daily food intake and discovered that by eating 5 portions of fruit and veg a day, I was not achieveing the rda of all the nutrients. In fact to do so a person has to eat a really wide range of fruit and veg and in quite large quantities. Americas 7 a day advice is better, but still, it depends on what you choose. It is a complicated science really.
This post is about amino acids in protein though, it is a huge subject, but really important for vegetarians to get to grips with, as amino acids are the building blocks of life. Every part of the human bodily system requires amino acids to function and renew. From blood, skin and cartilage, to muscles and bones, hormones and enzymes. It is all very well taking a multi vitamin, but without amino acids, the vitamins and minerals will have nothing to act with.
Personally as a vegetarian for many years, I now have a couple of scoops of whey protein powder daily, to be certain that my body always has a good supply of these treasures. It also saves me having to think too much about combining other protein sources and I do like to keep my life simple!
Essential Amino Acids Important Functions In The Body:
Isoleucine (Ile) - for muscle production, maintenance and recovery after workout. Involved in hemoglobin formation, blood sugar levels, blood clot formation and energy.
Leucine (Leu) - growth hormone production, tissue production and repair, prevents muscle wasting, used in treating conditions such as Parkinson’s disease.
Lysine (Lys) - calcium absorption, bone development, nitrogen maintenance, tissue repair, hormone production, antibody production.
Methionine (Met) - fat emulsification, digestion, antioxidant (cancer prevention), arterial plaque prevention (heart health), and heavy metal removal.
Phenylalanine (Phe) - tyrosine synthesis and the neurochemicals dopamine and norepinephrine. Supports learning and memory, brain processes and mood elevation.
Threonine (Thr) monitors bodily proteins for maintaining or recycling processes.
Tryptophan (Trp) - niacin production, serotonin production, pain management, sleep and mood regulation.
Valine (Val) helps muscle production, recovery, energy, endurance; balances nitrogen levels; used in treatment of alcohol related brain damage.
Histidine (His) - the 'growth amino' essential for young children. Lack of histidine is associated with impaired speech and growth. Abundant in spirulina, seaweed, sesame, soy, rice and legumes.
cite
Usually the protein content of various food is labelled in grams, but not all protein is equal. The combination of amino acids that make up the protein does matter.
For example, a person could get (for example) 10g protein from 100g wholewheat bread. However the human body would be unable to utilise all that protein, as wheat protein does not contain all the essential amino acids (the amino acids that the body has to be fed, as it can not make them itself). A food that contains all the essential amino acids is called a "complete protein". Vegetarian sources are dairy products, quinoa, soya. A food that contains protein but not all the essential amino acids is called an incomplete protein. An incomplete protein has some amino acids that limit it, these are called "limiting amino acids". In wheat (and most grain) protein for example, the limiting amino acid is lysine. As the body uses amino acids together to do stuff, in a ratio, it can therefor only process as much protein as the limiting amino acid allows.
So that is why it is necessary to complement vegetarian protein sources sometimes. For example mixing wheat or rice protein, with a legume protein (rice and dal, beans on toast, tortilla and refreid beans), results in all essential amino acids being present. As although wheat and rice lack lysine,it has plenty of methionine and tryptophan. Legumes are high in lysine, but low in methionine and tryptophan. Together they form a complementary protein.
I found a good utility online to check the amino acid profile of foods (from the USDA database)
Amino Acid Check
This can help to choose a variety of foods over a course of a day that will complement each other, so providing enough of all the essential amino acids.
I was surprised to see that most green vegetables, spinach, broccoli etc, in fact have excellent amino acid profiles, with all the essential amino acids contained. Obviously you would have to eat alot of greens to get the rda of protein, but I have read that our ancestors, in paleolithic times, might have eaten several carrier bag fulls of green leafy veg a day.
An interesting fact for weight watchers, is that 600g of broccoli, contains nearly 20g protein and under 150 calories. Weight watchers usually like to eat food that keeps them nice and full up without having too many cals. The equivalent calorie amount of rice, would be just around 35g, and would only provide about 3g protein. If hungry, I know which choice i would go for to keep me full for longer!
As a side note, recent reports state that eating broccoli along with something spicy such as mustard or horseradish, boosts it anto cancer properties. Vegetables have so many wonderful properties, that are only just being discovered.
I once used the USDA database to analyse my daily food intake and discovered that by eating 5 portions of fruit and veg a day, I was not achieveing the rda of all the nutrients. In fact to do so a person has to eat a really wide range of fruit and veg and in quite large quantities. Americas 7 a day advice is better, but still, it depends on what you choose. It is a complicated science really.
This post is about amino acids in protein though, it is a huge subject, but really important for vegetarians to get to grips with, as amino acids are the building blocks of life. Every part of the human bodily system requires amino acids to function and renew. From blood, skin and cartilage, to muscles and bones, hormones and enzymes. It is all very well taking a multi vitamin, but without amino acids, the vitamins and minerals will have nothing to act with.
Personally as a vegetarian for many years, I now have a couple of scoops of whey protein powder daily, to be certain that my body always has a good supply of these treasures. It also saves me having to think too much about combining other protein sources and I do like to keep my life simple!
Essential Amino Acids Important Functions In The Body:
Isoleucine (Ile) - for muscle production, maintenance and recovery after workout. Involved in hemoglobin formation, blood sugar levels, blood clot formation and energy.
Leucine (Leu) - growth hormone production, tissue production and repair, prevents muscle wasting, used in treating conditions such as Parkinson’s disease.
Lysine (Lys) - calcium absorption, bone development, nitrogen maintenance, tissue repair, hormone production, antibody production.
Methionine (Met) - fat emulsification, digestion, antioxidant (cancer prevention), arterial plaque prevention (heart health), and heavy metal removal.
Phenylalanine (Phe) - tyrosine synthesis and the neurochemicals dopamine and norepinephrine. Supports learning and memory, brain processes and mood elevation.
Threonine (Thr) monitors bodily proteins for maintaining or recycling processes.
Tryptophan (Trp) - niacin production, serotonin production, pain management, sleep and mood regulation.
Valine (Val) helps muscle production, recovery, energy, endurance; balances nitrogen levels; used in treatment of alcohol related brain damage.
Histidine (His) - the 'growth amino' essential for young children. Lack of histidine is associated with impaired speech and growth. Abundant in spirulina, seaweed, sesame, soy, rice and legumes.
cite
Wednesday, October 12, 2011
PHP - Get the last day of a month
<?php
function GetLastDayofMonth($year, $month) {
for ($day=31; $day>=28; $day--) {
if (checkdate($month, $day, $year)) {
return $day;
}
}
}
?>
Then to call the last day of the month
$lastdayofmonth = GetLastDayofMonth(2011, 02);
echo $lastdayofmonth;
This would print the last day of the month of February 2011
The function is in the notes for the checkdate php function at
http://php.net/manual/en/function.checkdate.php
Thursday, September 08, 2011
Jquery - submit form without page refresh and show php processed results
THE JQUERY
$(document).ready(function(){
$(".button").click(function() {
$.post("thephp.php", $("#saywhatform").serialize() ,
function(data) {
$('#results').html("Data Loaded: " + data);
});
return false;
});
});
THE HTML
<form id="saywhatform" action="">
<input type="text" name="something">
<a href=""><span class="button">Click Here</span></a>
</form>
<div id="results"></div>
THE PHP
$form_entry=$_POST['something'];
echo "You entered".$form_entry.";
So this code will allow a form to be submitted without a page refresh, the results processed by a php script and any results from the php can be printed put in a div on the page.
$(document).ready(function(){
$(".button").click(function() {
$.post("thephp.php", $("#saywhatform").serialize() ,
function(data) {
$('#results').html("Data Loaded: " + data);
});
return false;
});
});
THE HTML
<form id="saywhatform" action="">
<input type="text" name="something">
<a href=""><span class="button">Click Here</span></a>
</form>
<div id="results"></div>
THE PHP
$form_entry=$_POST['something'];
echo "You entered".$form_entry.";
So this code will allow a form to be submitted without a page refresh, the results processed by a php script and any results from the php can be printed put in a div on the page.
Monday, September 05, 2011
Jquery Datepicker - change Min Max dates on change of select box to values retrieved from mysql db
Using jquery datepicker, it is possible to restrict the date range available for selection
http://jqueryui.com/demos/datepicker/#min-max
I wanted the min and max dates to be dynamic variables based on mysql query results, that would change depending which value was selected in a select drop down.
To do this I created a php file that took the select drop down value and queried the database to return dates relevant to that value. Then outside the php tags, I put a javascript function, echoing the php variables as min max dates in two functions that could be called later using getscript().
Then all that is required is in the page where the datepicker is displayed, in the head section use .getscript() to get the variable jquery/javascript functions and apply them to various events, such as document.ready and .change of the select box value.
(The values of the select box are got using http://www.texotela.co.uk/code/jquery/select/ and passed as parameters on the url to the php script, where they are retrieved using $_GET['account'])
nb. The date needs to be correctly formatted, which can be done in the php code after retrieval from the db. The format of the date that is in the javascript function is like this:
YYYY, mm -1, dd
<script>
$(document).ready(function() {
var account = $("#accountselect").selectedValues();
$.getScript("restrictdates.php?account="+account+"", function() {minMax(); });
$('#accountselect').change(function() {
var account = $("#accountselect").selectedValues();
$.getScript("restrictdates.php?account="+account+"", function() {updateDate(); });
});
});
</script>
<select id="accountselect">
<option value="ac1">ac1</option>
<option value="ac1">ac1</option>
</select>
<input id="datepicker" type="text">
The restrictdates.php file is as follows...
<?php
$account=$_GET['account'];
//some php code here to retrieve specific $min and $max dates from database, for the relevant account
?>
function minMax() {
$("#datepicker" ).datepicker({
minDate: new Date(<?php echo $min; ?> ),
maxDate: new Date(<?php echo $max; ?>)
});
}
function updateDate() {
$( "#datepicker").datepicker('change',{
minDate: new Date(<?php echo $min; ?> ),
maxDate: new Date(<?php echo $max; ?>)
});
}
http://jqueryui.com/demos/datepicker/#min-max
I wanted the min and max dates to be dynamic variables based on mysql query results, that would change depending which value was selected in a select drop down.
To do this I created a php file that took the select drop down value and queried the database to return dates relevant to that value. Then outside the php tags, I put a javascript function, echoing the php variables as min max dates in two functions that could be called later using getscript().
Then all that is required is in the page where the datepicker is displayed, in the head section use .getscript() to get the variable jquery/javascript functions and apply them to various events, such as document.ready and .change of the select box value.
(The values of the select box are got using http://www.texotela.co.uk/code/jquery/select/ and passed as parameters on the url to the php script, where they are retrieved using $_GET['account'])
nb. The date needs to be correctly formatted, which can be done in the php code after retrieval from the db. The format of the date that is in the javascript function is like this:
YYYY, mm -1, dd
eg: 2011,01 -1 ,01
<script>
$(document).ready(function() {
var account = $("#accountselect").selectedValues();
$.getScript("restrictdates.php?account="+account+"", function() {minMax(); });
$('#accountselect').change(function() {
var account = $("#accountselect").selectedValues();
$.getScript("restrictdates.php?account="+account+"", function() {updateDate(); });
});
});
</script>
<select id="accountselect">
<option value="ac1">ac1</option>
<option value="ac1">ac1</option>
</select>
<input id="datepicker" type="text">
The restrictdates.php file is as follows...
<?php
$account=$_GET['account'];
//some php code here to retrieve specific $min and $max dates from database, for the relevant account
?>
function minMax() {
$("#datepicker" ).datepicker({
minDate: new Date(<?php echo $min; ?> ),
maxDate: new Date(<?php echo $max; ?>)
});
}
function updateDate() {
$( "#datepicker").datepicker('change',{
minDate: new Date(<?php echo $min; ?> ),
maxDate: new Date(<?php echo $max; ?>)
});
}
Tuesday, July 26, 2011
PHP - Is it a leap year?
After spending 20 minutes writing a short function to test a date to see if it is a leap year, I find that php has a built in date function to do the job. Never mind it was interesting anyway to discover that there is a method in the madness of leap years. According to wikipedia, if a year is divisible by 4 it is a leap year. But not if it is divisible by 100, unless it is divisible by 400....get it?
So this was my waste of time leap year calculating function..
<?php
$year = date('Y') ;
if ( $year %400 == 0 ) { $isleap = 'yes' ; }
elseif ( $year %100 == 0 ) { $isleap = 'no' ; }
elseif ( $year %4 == 0 ) { $isleap = 'yes' ; }
else {$isleap='no';}
if ( $isleap == 'yes')
{echo $year." is a leap year";}
else
{echo $year." is not a leap year";}
?>
The smart way to do it though is just with date('L'), this php function returns 1 if it is a leap year and 0 if it is not...much simpler...
<?php
$year=date('Y');
$isleap = date('L') ;
if ( $isleap == '1')
{echo $year." is a leap year";}
else
{echo $year." is not a leap year";}
?>
So this was my waste of time leap year calculating function..
<?php
$year = date('Y') ;
if ( $year %400 == 0 ) { $isleap = 'yes' ; }
elseif ( $year %100 == 0 ) { $isleap = 'no' ; }
elseif ( $year %4 == 0 ) { $isleap = 'yes' ; }
else {$isleap='no';}
if ( $isleap == 'yes')
{echo $year." is a leap year";}
else
{echo $year." is not a leap year";}
?>
The smart way to do it though is just with date('L'), this php function returns 1 if it is a leap year and 0 if it is not...much simpler...
<?php
$year=date('Y');
$isleap = date('L') ;
if ( $isleap == '1')
{echo $year." is a leap year";}
else
{echo $year." is not a leap year";}
?>
Tuesday, July 19, 2011
mysql compare two large tables - find records only in 1 table - for sitemap last modified date
I needed to compare two large tables each having over 2 million records and find the records that are in table 1 but not in table 2.
I only wanted the records from table 1 and not all records that were different from both tables, so on each select query I added a temporary column that stated which table the result was from, so that after the insert select, those with table2 in the temp column could be deleted, leaving just the table 1 records...which are new records that have been added to a database since the last update.
The UNION results are inserted into a new table, so that after being inserted, all records from table2 can be deleted...
INSERT INTO products_new (name,merchantid,tab)
SELECT MIN( name ) AS name, merchantid, tab
FROM (
SELECT name, merchantid, 'table1' AS tab
FROM products_import AS alias1
UNION ALL SELECT name, merchantid, 'table2' AS tab
FROM products_bak AS alias2
)AS alias_table
GROUP BY name
HAVING COUNT( name ) =1
ORDER BY name
So after populating the new products table, the records that were only in table 2 can be deleted, leaving a table with the unique values from table 1.
DELETE FROM products_new WHERE tab='table2'
I have used this in order to be able to make my sitemaps last modified date more accurate, as currently at each product update, all dynamically created product pages have a recent last modified date, even if they were previously present in the DB. Using this method, the last modified date of new products can be accurately shown as new pages, by accessing this new table.
I only wanted the records from table 1 and not all records that were different from both tables, so on each select query I added a temporary column that stated which table the result was from, so that after the insert select, those with table2 in the temp column could be deleted, leaving just the table 1 records...which are new records that have been added to a database since the last update.
The UNION results are inserted into a new table, so that after being inserted, all records from table2 can be deleted...
INSERT INTO products_new (name,merchantid,tab)
SELECT MIN( name ) AS name, merchantid, tab
FROM (
SELECT name, merchantid, 'table1' AS tab
FROM products_import AS alias1
UNION ALL SELECT name, merchantid, 'table2' AS tab
FROM products_bak AS alias2
)AS alias_table
GROUP BY name
HAVING COUNT( name ) =1
ORDER BY name
So after populating the new products table, the records that were only in table 2 can be deleted, leaving a table with the unique values from table 1.
DELETE FROM products_new WHERE tab='table2'
I have used this in order to be able to make my sitemaps last modified date more accurate, as currently at each product update, all dynamically created product pages have a recent last modified date, even if they were previously present in the DB. Using this method, the last modified date of new products can be accurately shown as new pages, by accessing this new table.
Increase size of tmpDSK cPanel
The default temp partion size in cpanel is 512mb which is usually not enough and creates errors such as "Drive Critical: /usr/tmpDSK (/tmp) is 99% full".
It can be increased as follows using the following commands....
It can be increased as follows using the following commands....
stop services, mysql,apache and cpanel
root@server [~]# /etc/init.d/mysql stop
root@server [~]# /etc/init.d/httpd stop
root@server [~]# /etc/init.d/cpanel stop
backup the /tmp folder
root@server [~]# cp -rfp /tmp /tmp_backup
lazy unmount of /tmp
root@server [~]# umount -l /tmp
remove tmpDSK
root@server [~]# rm -rf /usr/tmpDSK
edit securetmp script, find my $tmpdsksize = 512000; # Must be larger than 250000
increase to necessary for example 2gb my $tmpdsksize = 2072000;
root@server [~]# nano /scripts/securetmp
run securetmp script to recreate /tmp (tmpDSK) partition at size specified
root@server [~]# /scripts/securetmp
root@server [~]# /etc/init.d/mysql stop
root@server [~]# /etc/init.d/httpd stop
root@server [~]# /etc/init.d/cpanel stop
backup the /tmp folder
root@server [~]# cp -rfp /tmp /tmp_backup
lazy unmount of /tmp
root@server [~]# umount -l /tmp
remove tmpDSK
root@server [~]# rm -rf /usr/tmpDSK
edit securetmp script, find my $tmpdsksize = 512000; # Must be larger than 250000
increase to necessary for example 2gb my $tmpdsksize = 2072000;
root@server [~]# nano /scripts/securetmp
run securetmp script to recreate /tmp (tmpDSK) partition at size specified
root@server [~]# /scripts/securetmp
Monday, July 11, 2011
Bash - loop through files updated in last 7 days
From command line or in a bash script, to loop thorugh all files that have been updated in the last however many days (in this example 7)...use the FIND command...
FILES=$(find /path/to/directory/ -type f -mtime -7)
for f in $FILES
do
echo $f
done
FILES=$(find /path/to/directory/ -type f -mtime -7)
for f in $FILES
do
echo $f
done
Saturday, July 09, 2011
php to display mysql query results in html table
The following code would go in an html document (that is able to display php) and display dynamic results from a mysql table into the table. This example builds a table that is 3 columns width, so the code to write the table is based on the number of rows returned from the mysql result, adding extra empty cells at the end if required.
A screen shot below, shows how the numbers are counted through to write the necessary html code to display the mysql results. In this example 19 rows are returned from mysql, so two extra table cells were required at the end, as 7 rows of 3 cells is 21 cells required. The table cells broke with a row after every count of 3.

<!-- open the table tags in the html document -->
<table border="1px"><tr>
<?php
//select the columns required from the mysql table
$result=mysql_query("SELECT name,description FROM gifts ORDER BY name");
//get count of rows returned
$numrows=mysql_num_rows($result);
//for a table with 3 columns divide the number of results by 3 and round up
$numtr=ceil($numrows/3);
//get the remainder
$remainder=$numrows % 3;
//from that calculate how many extra table cells are required in the final row
$xtratd=3-$remainder;
$i=1;//count for <td>
$x=1;//count for <tr>
//loop through $result declaring variables for any result required to go in the table
while($row=mysql_fetch_array($result))
{
$catname=$row['name'];
$catdesc=$row['description'];
//for demo purposes the values of $x and $i are shown in the table cells here
echo "<td>$i is ".$i."<br />$x is ".$x."<br /></td>";
//this line starts and end a new row in the table and increments the count of table rows (tr)
if(($i % 3 == 0) && ($x!=$numtr)){echo "</tr><tr>";$x++;}
//if the total number of rows is reached get how many extra table cells are needed and write them, then close the final row
if($i==$numrows)
{
for($z=1;$z<=$xtratd;$z++){
echo "<td>$xtratd is ".$z."</td>";
}
echo "</tr>";
}
$i++;//increment the count of table cells (td)
}
?>
<!-- close the table tags in the html document -->
</table>
MYSQL - Update one columns data from another table
To copy one columns data to another existing tables column in mysql, it is possible with an update query like this :
UPDATE table1,table2
SET table1.coltocopy=table2.coltocopy
WHERE table1.coltocompare=table2.coltocompare;
UPDATE table1,table2
SET table1.coltocopy=table2.coltocopy
WHERE table1.coltocompare=table2.coltocompare;
Tuesday, July 05, 2011
PHP - Limit A Loop - FOREACH,WHILE etc
If you just want to loop through (for example) 2 iterations of a loop, rather than returning the whole set of data, you can insert a break clause to limit the number of times the data is looped through and so limit the results to two iterations.
$i = 0;
foreach($vars as $var){
//code to run
if(++$i > 2) break;
}
$i = 0;
foreach($vars as $var){
//code to run
if(++$i > 2) break;
}
Monday, June 27, 2011
PHP - Assign variable names to array elements from mysql query
It is useful to be able to take the results of a MYSQL query and assign variable names to the results, so that they can be used later on in a script.
This can be done simply as follows...
$result= mysql_query("SELECT id FROM table WHERE num='567' LIMIT 3") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$ids[] = $row['id'];
}
$id1 = $ids[0];
$id2 = $ids[1]
$id3 = $ids[2];
So you now have 3 variables fetched from the mysql array that can be used outside of a loop.
This specific example limits the mysql result to 3. However you could do this for any (change the 3 to how many results you want) and unknown numbers of results doing a COUNT of returned results and then iterating based on that number.
This can be done simply as follows...
$result= mysql_query("SELECT id FROM table WHERE num='567' LIMIT 3") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$ids[] = $row['id'];
}
$id1 = $ids[0];
$id2 = $ids[1]
$id3 = $ids[2];
So you now have 3 variables fetched from the mysql array that can be used outside of a loop.
This specific example limits the mysql result to 3. However you could do this for any (change the 3 to how many results you want) and unknown numbers of results doing a COUNT of returned results and then iterating based on that number.
Monday, June 20, 2011
Price Comparison Site Relaunched
FindAllSorts.com and FindAllSorts.co.uk were relaunched this week.
FindAllSorts has been split across two domains, one for the UK price comparisons and one for the USA price comparisons.
The site has been rebuilt and improved in both functionality and design. New features are available, the search is better, with the ability to filter product search results so users can be more specific as to what brands or stores or price they wish to check.
There is also a discount vouchers section, where all the online stores discount vouchers are shown and searchable. all coupon codes and special offers are updated daily with details of how long the offer or code will be valid for. So when buying a product it is a good place to check to see if a discount may be available.
UK Price Comparison Site - Find and compare prices of products in the UK. Find discount vouchers, coupon codes and special offers to get yourself the best deal.
USA Price Comparison Site - Find and compare prices of products in the USA. Find discount vouchers, coupon codes and special offers, to get yourself the best deal.
Amazon and Ebay products will also soon be included.
Compare prices to find the best deals at FindAllSorts!
FindAllSorts has been split across two domains, one for the UK price comparisons and one for the USA price comparisons.
The site has been rebuilt and improved in both functionality and design. New features are available, the search is better, with the ability to filter product search results so users can be more specific as to what brands or stores or price they wish to check.
There is also a discount vouchers section, where all the online stores discount vouchers are shown and searchable. all coupon codes and special offers are updated daily with details of how long the offer or code will be valid for. So when buying a product it is a good place to check to see if a discount may be available.
UK Price Comparison Site - Find and compare prices of products in the UK. Find discount vouchers, coupon codes and special offers to get yourself the best deal.
USA Price Comparison Site - Find and compare prices of products in the USA. Find discount vouchers, coupon codes and special offers, to get yourself the best deal.
Amazon and Ebay products will also soon be included.
Compare prices to find the best deals at FindAllSorts!
Subscribe to:
Posts (Atom)
