[PHP] Problem with date
Hi, I have a problem with date function. $gen_pos = mktime(0,0,1,10,25,2009); $d1 = date("Y-m-d", $gen_pos); // 2009-10-25 $d2 = date("Y-m-d", $gen_pos + (1*24*60*60)); // 2009-10-25 $d3 = date("Y-m-d", $gen_pos + (2*24*60*60)); // 2009-10-26 $d4 = date("Y-m-d", $gen_pos + (3*24*60*60)); // 2009-10-27 $d5 = date("Y-m-d", $gen_pos + (4*24*60*60)); $d6 = date("Y-m-d", $gen_pos + (5*24*60*60)); $d7 = date("Y-m-d", $gen_pos + (6*24*60*60)); $d8 = date("Y-m-d", $gen_pos + (7*24*60*60)); line 2 and line 3 return same date,its wrong ... it should be 2009-10-25 , 2009-10-26 ? :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SQL - RANDOM
thx it looks good [EMAIL PROTECTED] napsal(a): For large tables, I generally create a "static_rand" column, and pre-populated it with random numbers and create an index on it. Then, after "using up" the records, I have application logic to reset those records (and only those records) to new random numbers. This provides MUCH better performance than using rand() on huge tables. alter table whatever add static_rand float; create index rand_index on whatever(static_rand); select id from whatever order by static_rand limit 3; -- PHP code to create an array of the 3 IDs you got: $ids_sql = implode(',', $ids); $query = "update whatever set static = rand() where id in ($ids_sql)"; It's a bit crude in that you have to remember to do the UPDATE, but quite fast, and not THAT tricky to modularize your code to always do the UPDATE. Or not, actually, if it's okay to "cache" the random answer for a short period of time. Then you can just have a cron job that does: update whatever set static_rand = rand() order by static_rand limit 3; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SQL - RANDOM
Hi, i would ask what is the best method for random select from database. I have table with 20k items.. - If i use ,,select * from table order by rand() limit 3", the query took 0.0524 sec ... its slightly enough - but if i generate rand id and then i use ,,select where id in(rand1, rand2, rand3), the query took only 0.0005 sec, but there is a problem that id doesnt exist thanks for responses -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bug in array_key_exist?
Korgan napsal(a): Jim Lucas napsal(a): Korgan wrote: Hi, I have a problem with array_key_exists in if statement. I have a class with this function class XXX { private items = array(); ... ... ... public function addXXX($id, $count) { $count = (int)$cout; Let me point at it Check your spelling If error_reporting was set to E_ALL AND display_errors were turned on, you would see that you are using an undefined variable in your method called $cout, casting is as an int and assigning the resulting value (which would always be zero) to $count. Sorry i didnt see it :). In the script is $count = (int)$count; After add a item value is ok look at first B vardump which is on the end of the script. No variable $count is mandatory so that is defined. But its not main idea of my question... Function add items correctly, but if go to next page, values in array change. Values are changed passing from one page to another one, why and where? if (!array_key_exists($id, $this->items)) $this->items[$id] = $count; else $this->items[$id] += $count; } ... ... } And I want to send instance of this class with SESSION. If I add a item to the array, count is ok, but if i go to the next page count will change. There is the code of index.php /** its loading classes ***/ spl_autoload_register('loadClass'); session_start(); var_dump($_SESSION['XX']); /** A **/ ... ... ... if ($_SESSION['XX'] instanceof XXX) $x = $_SESSION['XX']; else new... .. .. /** Do onzl this **/ if $x->addXXX($id, $cnt); ... ... $_SESSION['XX'] = X; var_dump($_SESSION['XX']); /** B **/ There is a vardump if action addXXX exec: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(0) { } } B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(1) } } And than i will go to some page and vardums are: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } 1 : 4 B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } I am thinking that do both codes in if statement, but $this->items[$id] += $count; exec after send page. I am using PHP Version 5.2.6 and Smarty v.2.6.19 Thanks for help :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bug in array_key_exist?
Jim Lucas napsal(a): Korgan wrote: Hi, I have a problem with array_key_exists in if statement. I have a class with this function class XXX { private items = array(); ... ... ... public function addXXX($id, $count) { $count = (int)$cout; Let me point at it Check your spelling If error_reporting was set to E_ALL AND display_errors were turned on, you would see that you are using an undefined variable in your method called $cout, casting is as an int and assigning the resulting value (which would always be zero) to $count. No variable $count is mandatory so that is defined. But its not main idea of my question... Function add items correctly, but if go to next page, values in array change. Values are changed passing from one page to another one, why and where? if (!array_key_exists($id, $this->items)) $this->items[$id] = $count; else $this->items[$id] += $count; } ... ... } And I want to send instance of this class with SESSION. If I add a item to the array, count is ok, but if i go to the next page count will change. There is the code of index.php /** its loading classes ***/ spl_autoload_register('loadClass'); session_start(); var_dump($_SESSION['XX']); /** A **/ ... ... ... if ($_SESSION['XX'] instanceof XXX) $x = $_SESSION['XX']; else new... .. .. /** Do onzl this **/ if $x->addXXX($id, $cnt); ... ... $_SESSION['XX'] = X; var_dump($_SESSION['XX']); /** B **/ There is a vardump if action addXXX exec: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(0) { } } B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(1) } } And than i will go to some page and vardums are: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } 1 : 4 B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } I am thinking that do both codes in if statement, but $this->items[$id] += $count; exec after send page. I am using PHP Version 5.2.6 and Smarty v.2.6.19 Thanks for help :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Bug in array_key_exist?
Error reporting is set on E_ALL notice: it change value if I add the item which isnt in array Lupus Michaelis wrote: Korgan a écrit : public function addXXX($id, $count) { $count = (int)$cout; Try to work with error_reporting set to E_ALL ;) session_start(); var_dump($_SESSION['XX']); /** A **/ If XX is a right value for a variable name, they are no problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Bug in array_key_exist?
Hi, I have a problem with array_key_exists in if statement. I have a class with this function class XXX { private items = array(); ... ... ... public function addXXX($id, $count) { $count = (int)$cout; if (!array_key_exists($id, $this->items)) $this->items[$id] = $count; else $this->items[$id] += $count; } ... ... } And I want to send instance of this class with SESSION. If I add a item to the array, count is ok, but if i go to the next page count will change. There is the code of index.php /** its loading classes ***/ spl_autoload_register('loadClass'); session_start(); var_dump($_SESSION['XX']); /** A **/ ... ... ... if ($_SESSION['XX'] instanceof XXX) $x = $_SESSION['XX']; else new... .. .. /** Do onzl this **/ if $x->addXXX($id, $cnt); ... ... $_SESSION['XX'] = X; var_dump($_SESSION['XX']); /** B **/ There is a vardump if action addXXX exec: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(0) { } } B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(1) } } And than i will go to some page and vardums are: A: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } 1 : 4 B: object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } I am thinking that do both codes in if statement, but $this->items[$id] += $count; exec after send page. I am using PHP Version 5.2.6 and Smarty v.2.6.19 Thanks for help :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php