2009/11/05

two select

Two selects:

SELECT cart_name as tag, count(cart_name) as frequency
From
  (SELECT distinct cart_name , account_id
   FROM `account_cart`
   where cart_name REGEXP '^[a-z]+'
) as tb1
Group by cart_name



2009/11/03

empty matches 0 in sql????

page_id = '', the following sql still work.

SELECT SQL_CACHE a.unique_id, b.banner_id, a.page_id, a.grp, a.page_pos,
a.order_seq, b.banner_type, b.image_name, b.link, b.target, b.params, ''
AS sku_list
FROM page_banners_link a, page_banners b
WHERE a.page_id = ''
AND site_id = '0'
AND a.banner_id = b.banner_id
ORDER BY a.page_pos, a.page_id, a.order_seq
LIMIT 0 , 30

2009/11/02

how to purge master logs

> on master:    mysql -p

> 

> mysql >  show master status;

> 

> 

> on slave:   mysql -p

> 

> mysql > show slave status;

> 

> 

> If both master and slave are processing the same replication log file

> (meaning that replication is running correctly),  then you can safely

> run the following commend on master:

> 

> 

> mysql > purge master logs to "current-replication-log-filename";

 

2009/10/26

window.location

function onSelectChangeSite(){
   var dropdown = document.getElementById("snssite");
   var index = dropdown.selectedIndex;
   var ddVal = dropdown.options[index].value;

   var current = window.location;
   var re1 = /\?custm/;
   var re2 = /\?/;

   if (re1.test(current))
      window.location = "?custm=" + ddVal;
   else if (re2.test(current))
      window.location = current + "&custm=" + ddVal;
   else
      window.location = "?custm=" + ddVal;

}

2009/10/25

perl note part2

1.      @line= <STDIN>

Chomp(@line)

print @line;

CTR+D in linux CTR+Z in window to end of standard input

2.      A lot of default

Sub list_from_a_to_b{

            If ($a>$b){

            $a;

            }

            Else{

            $b;

            }

}

$a, $b are global variables. No return needed

Or use

Sub list_from_a_to_b{

            ($a,$b) = @_

Or use

$a = $_[0];

$b = $_[1];

 

2009/10/23

perl note part1

Perl does not have Boolean type true/false

Chomp chops new line, but chop chops the last char

Below does not work in php ($sum UNDEF), but works in perl (unless warning/strict turn on)

$n=1;

while($n<10){

$sum += $n++;

}

print $sum;

qw shortcut

qw /fred barney betty Wilma dino/ == (“fred”, “barney” …)

@array = 6..9

Push/pop operators do things to the end of an array, but shift/unshift do things to the begin of an array

for (1..9){ print;} == for (1..9) {print $_;}

sort/reverse functions does not change the array itself, but return a sorted/reversed array

2009/10/20

more xml encode

function xml_encode($str) {
   $str = preg_replace("/".chr(153)."/","(tm)",$str); // trademark
   $str = preg_replace("/".chr(174)."\s/","(r) ",$str); // registered tratemark
   $str = preg_replace("/".chr(174)."\W?/","(r)",$str); // registered tratemark
   $str = preg_replace("/".chr(169)."/","",$str); // copyright
   $str = preg_replace("/".chr(194)."/","",$str); // Capital A, circumflex accent

   $str = preg_replace("/&reg;/","(r)",$str);
   $str = preg_replace("/&quot;/","\"",$str);
   $str = preg_replace("/&#153;/","(tm)",$str);
   return $str;
}