php-general Digest 20 Oct 2010 12:36:59 -0000 Issue 6997

2010-10-20 Thread php-general-digest-help

php-general Digest 20 Oct 2010 12:36:59 - Issue 6997

Topics (messages 308865 through 308882):

Re: simple class  constructor
308865 by: David McGlone
308866 by: David McGlone
308867 by: David Harkness
308868 by: Tommy Pham
308869 by: David McGlone
308870 by: Jay Blanchard
308871 by: David McGlone
308872 by: David McGlone

Re: Fiscal Years and Quarters
308873 by: admin.buskirkgraphics.com
308875 by: admin.buskirkgraphics.com

Possible foreach bug; seeking advice to isolate the problem
308874 by: Jonathan Sachs
308876 by: richard gray
308877 by: Gary
308881 by: Tommy Pham

Re: PHP stream_socket_client OpenSSL error (unknown ca)
308878 by: Richard

Unicode - Entitiy Encoding
308879 by: Sebastian Detert

Error handler script
308880 by: Teto

Re: Firs Day Of Week UNIX
308882 by: Richard Quadling

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Tue, 2010-10-19 at 16:53 -0700, Tommy Pham wrote:
  -Original Message-
  From: David McGlone [mailto:da...@dmcentral.net]
  Sent: Tuesday, October 19, 2010 4:32 PM
  To: php-gene...@lists.php.net
  Subject: Re: [PHP] simple class  constructor
  
  On Tue, 2010-10-19 at 17:15 -0400, Paul M Foster wrote:
   On Tue, Oct 19, 2010 at 04:12:51PM -0400, David McGlone wrote:
  snip
   You're trying to instantiate the class. And the way you're doing it
   here is correct. When you do this, $test becomes an object of this
   class. If you had another function (member) within the class called
   myfunction(), you could run it this way (after you instantiate the
   class):
  
   $test-myfunction();
  
   
Basically I want to learn how I can (if it's possible with this
simple
code) is display the output on a different page.
   
I tried putting the line: $test=new simpleConstructer(); on the
index page and including the page the class is on, but it causes the
index page to go blank.
  
   You've likely got an error you're not seeing. Fix this first. If the
   file your class is in is syntactically correct, and you do
  
   include simpleConstructerFile.php;
  
   in your index.php file, it should flawlessly include the code. Then,
   in your index.php, you do this:
  
   $test = new simpleConstructer;
  
   you should see the contents of the echo statement appear on the page.
   So you're on the right track. You just need to find the error first.
  
  
  Ah ha! Thank you! Your mention of an error, was spot on. notice below I
  misspelled the class name but got the Object name correct.
  
  Also at first I had the setup like this because it wasn't working and I 
  thought
  I was doing it wrong: (this also added to my confusion)
  
  myclass.php
  
  class simpleConstructer {
  
  function __construct() {
  echo running the constructor;
 }
  }
  
  index.php
  require_once 'myclass.php';
  $test = new simpleConstructor();
  
  But once I fixed the error I put it all back in myclass.php like so:
  
  myclass.php
  
  class simpleConstructer {
  
  function __construct() {
  echo running the constructor;
 }
  }
  $test = new simpleConstructor();
  
  
  Now I am wondering what you meant when you said:
  If you had another function (member) within the class called
  myfunction(), you could run it this way (after you instantiate the
   class):
  
  $test-myfunction();
  
  If you don't mind my asking, how would you take the above example and
  change it to what you describe above?
  
 
 class simpleConstructer {
  
 function __construct() {
  echo running the constructor;
}
 
 function myFunction() {
  echo 'this is another function/method within the class simpleConstructor';
   }
 }
 
 $test = new simpleConstructor();
 $test-myfunction();

Thank you Tommy.

Now it all comes together and I believe I understand now.

Does the code immediately after the __construct automatically run, but
when adding more methods to the class, they need to be called with the
$name-Object_name? Is my thinking correct?

-- 
Blessings
David M.

---End Message---
---BeginMessage---
On Tue, 2010-10-19 at 17:05 -0700, David Harkness wrote:
 Note that you still have a typo, but maybe it's only in your email messages:
 
  class simpleConstructer {
 
function __construct() {
  echo running the constructor;
}
  }
  $test = new simpleConstructor();
 
 The class is misspelled; it should be simpleConstructor. As a side note,
 it's common convention to name classes with a leading capital letter, e.g.
 SimpleConstructor. That's just convention, though, and I'm sure it differs
 in some 

Re: [PHP] Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread richard gray

 On 20/10/2010 05:47, Jonathan Sachs wrote:

I've got a script which originally contained the following piece of
code:

foreach ( $objs as $obj ) {
do_some_stuff($obj);
}

When I tested it, I found that on every iteration of the loop the last
element of $objs was assigned the value of the current element. I was
able to step through the loop and watch this happening, element by
element.


Are you are using a 'referencing' foreach? i.e.

foreach ($objs as $obj) {
do_some_stuff($obj);
}

or is the above code a direct lift from your script?

Referencing foreach statements can cause problems as the reference to 
the last array entry is persistent after the foreach loop has terminated 
so any further foreach statements on the same array will overwrite the 
previous reference which is still pointing to the last item.


Rich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)

2010-10-20 Thread Richard

 Hello again,

Just to say that I have tested the script on php.net manual that 
generates a cert and then trys to connect (slightly modified the end of 
file [removing the while(true) section to just test the connection]) and 
I get exactly the same error.


Source : http://php.net/manual/en/function.stream-socket-server.php

Here is the full test script :

?php
// Hello World! SSL HTTP Server.
// Tested on PHP 5.1.2-1+b1 (cli) (built: Mar 20 2006 04:17:24)

// Certificate data:
$dn = array(
countryName = UK,
stateOrProvinceName = Somerset,
localityName = Glastonbury,
organizationName = The Brain Room Limited,
organizationalUnitName = PHP Documentation Team,
commonName = Wez Furlong,
emailAddress = w...@example.com
);

// Generate certificate
$privkey = openssl_pkey_new();
$cert = openssl_csr_new($dn, $privkey);
$cert = openssl_csr_sign($cert, null, $privkey, 365);

// Generate PEM file
# Optionally change the passphrase from 'comet' to whatever you want, 
or leave it empty for no passphrase

$pem_passphrase = 'comet';
$pem = array();
openssl_x509_export($cert, $pem[0]);
openssl_pkey_export($privkey, $pem[1], $pem_passphrase);
$pem = implode($pem);

// Save PEM file
$pemfile = './server.pem';
file_put_contents($pemfile, $pem);

$context = stream_context_create();

// local_cert must be in PEM format
stream_context_set_option($context, 'ssl', 'local_cert', $pemfile);
// Pass Phrase (password) of private key
stream_context_set_option($context, 'ssl', 'passphrase', $pem_passphrase);

stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
stream_context_set_option($context, 'ssl', 'verify_peer', false);

// Create the server socket
$server = stream_socket_client('ssl://test.server.com:978', $errno, 
$errstr,30, STREAM_CLIENT_CONNECT, $context);


if($server)
{
print('ok');
}
?


I still get the error :
Warning: stream_socket_client(): SSL operation failed with code 1. 
OpenSSL Error messages:
error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca in 
/home/richard/test.php on line 44
I think this proves that it's not my certificate at fault but maybe a 
problem with OpenSSL…


What do you think ?

Thank you,

Richard

Le 19/10/10 20:46, Richard a écrit :

No I didn't have a passphrase on the local cert when I created it.

I noticed that I only sent it to you and then sent the same message to 
the list.


Thank you,

Richard

Le 19/10/10 20:28, Tommy Pham a écrit :

-Original Message-
From: Richard [mailto:php_l...@ghz.fr]
Sent: Tuesday, October 19, 2010 11:22 AM
To: Tommy Pham
Subject: Re: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)

I left the pasphrase blank, I've just tried with a blank passphrase but

it

doesn't help.

?php
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert',

'./afnic.pem');

stream_context_set_option($context, 'ssl', 'passphrase', '');
stream_context_set_option($context, 'ssl', 'allow_self_signed',

TRUE);

stream_context_set_option($context, 'ssl', 'verify_peer', FALSE);

$connexion = stream_socket_client('ssl://epp.test.nic.fr:700',
$errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($connexion) {
print('succes');
}
?

What I meant was that did you have a passphrase on your actual local 
cert

when you created it?

PS: Please cc the list also so others would know what's going and can 
help

troubleshoot and not reiterate what've been tried already.


Le 19/10/10 20:16, Tommy Pham wrote :

-Original Message-
From: Richard [mailto:php_l...@ghz.fr]
Sent: Tuesday, October 19, 2010 10:50 AM
To: php-general@lists.php.net
Subject: [PHP] PHP stream_socket_client OpenSSL error (unknown ca)

Hello,

I'm having some problems connecting to a server using the 
following php

script :

?php
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert',

'./cert.pem');

stream_context_set_option($context, 'ssl', 'allow_self_signed',

TRUE);

stream_context_set_option($context, 'ssl', 'verify_peer', FALSE);

$ctn = stream_socket_client('ssl://distant.server.com:987',

$errno,

$errstr,

30, STREAM_CLIENT_CONNECT, $context);
if($ctn) {
print('Connected !');
}
?

Just curious,

'passphrase string

Passphrase with which your local_cert file was encoded' quoted from

[1].

Regards,
Tommy

[1] http://us3.php.net/manual/en/context.ssl.php


cert.pem is a self signed certificate that I generated a few days 
ago,

it

contains both RSA Key and Certificate and I have supplied the

certificate

to

the distant server.

When I launch the script I get the following errors :

Warning: stream_socket_client(): SSL operation failed with code 1.
OpenSSL Error messages:
error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca in
/path/to/my/test.php on line 7

As it is a self signed certificate there is no CA so I added the two

lines

:

stream_context_set_option($context, 'ssl', 'allow_self_signed',

TRUE);

stream_context_set_option($context, 'ssl', 'verify_peer', 

[PHP] Unicode - Entitiy Encoding

2010-10-20 Thread Sebastian Detert

Hi all,

I'm stuck with this problem: I am trying to convert a text with any kind 
of unicode characters to its octet and entity equivalents.


For example:
Ë is #203; as octet and Euml; as entity
Đ is #272; as octet and Dstrok; as entity

My code works fine for some characters ( Ë works fine, but Đ fails at 
entity encoding). Do you have a hint, how to solve this?


I try to get the octet encoding with mb_encode_numericentity which works 
fine for everything


$convmap = array(
0x22, 0x22, 0, 0x, # 
0x26, 0x27, 0, 0x, # '
0x3c, 0x3c, 0, 0x, # 
0x3d, 0x3d, 0, 0x, # 
0x80, 0x, 0, 0x,
);
$oct_string = mb_encode_numericentity($test, $convmap, 'UTF-8');

I try to get all entity encodings with htmlentities

$entity_string = htmlentities($test, ENT_QUOTES, 'UTF-8');

But that fails for some characters like Đ. Is there a better way to get 
all entity encodings?


Thanks,
Sebastian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Error handler script

2010-10-20 Thread Teto
Hi,

I've been wondering if there was any php project focusing on providing
a neat php error handler ?
Up to now, I've been coding mine but I've seen videos on the web where
a guy was using a really impressive php error_handler. Of course I
could code it but if there was something generic I could use in
different projets,that could be useful.

Thx for any tip

matt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread Tommy Pham
 -Original Message-
 From: Gary [mailto:php-gene...@garydjones.name]
 Sent: Tuesday, October 19, 2010 11:38 PM
 To: php-general@lists.php.net
 Subject: [PHP] Re: Possible foreach bug; seeking advice to isolate the
 problem
 
 Jonathan Sachs wrote:
  I've got a script which originally contained the following piece of
  code:
 
  foreach ( $objs as $obj ) {
 do_some_stuff($obj);
  }
 
  When I tested it, I found that on every iteration of the loop the last
  element of $objs was assigned the value of the current element.
 
 I only had a few minutes to look at it, but here is my 2 Euro cents.
 
 It only occurs when you have previously done
 ,
 | foreach ( $objs as $obj ) {
 |//anything or nothing here
 | }
 `
 as described in the documentation.
 
  That leaves me with the question: what is going wrong with foreach?
  I'm trying to either demonstrate that it's my error, not the PHP
  engine's, or isolate the problem in a small script that I can submit
  with a bug report.
 
 From the post you reference in the manual's comments:
 $a = array('a', 'b','c');
 foreach($a as $row){
 //you don't have to do anything here
 }
 print_r($a);
 foreach($a as $row){
 echo br /.$row;
 }
 print_r($a);
 
 This suffices.
 
  I tried to eliminate the database by doing a var_export of the array
  after I built it, then assigning the exported expression to a variable
  immediately before the foreach. That broke the bug -- the loop
  behaved correctly.
 
 Yup. I guess whatever database code used previously was doing the
 equivalent of the first foreach in the previous code snippet.
 
  Can anyone make suggestions on this -- either insights into what's
  wrong, or suggestions for producing a portable, reproducible example?
 
 Better. I can tell you how to solve it:
 $a = array('a', 'b','c');
 foreach($a as $row){
 //you don't have to do anything here
 }
 unset($row); //  THIS IS KEY!

Shouldn't that be $row = null since unset will remove the last value, not
just removing the variable also, from the array whereas the $row = null will
tell the reference pointer that it doesn't point to a value.

 print_r($a);
 foreach($a as $row){
 echo br /.$row;
 }
 print_r($a);
 
 I admit though, it's not obvious, even from reading the manual, and is
 definitely a bug in the sense it is unexpected behaviour. Documenting it
 and calling it a feature is appalling.
 

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Firs Day Of Week UNIX

2010-10-20 Thread Richard Quadling
On 19 October 2010 14:59, Don Wieland d...@dwdataconcepts.com wrote:
 Hi gang,

 I need a bailout.

 I have a fields called sys_first_day_of_week and the user can select one
 value which will be from a menu with these options:

 Monday
 Tuesday
 Wednesday
 Thursday
 Friday
 Saturday
 Sunday

 Based on this Preference and TODAYS DATE, I want to calculate the first
 day of the week.

 So if my preference is Monday and Today's date is 10/19/2010, I want to
 return a value of: 1287374400 (which is 10/18/2010)

 if my preference is Wednesday and Today's date is 10/19/2010, I want to
 return a value of: 1286942400 (which is 10/13/2010)

 Appreciate any help.

 Don Wieland
 D W   D a t a   C o n c e p t s
 ~
 d...@dwdataconcepts.com
 Direct Line - (949) 336-4828

 Integrated data solutions to fit your business needs.

 Need assistance in dialing in your FileMaker solution? Check out our
 Developer Support Plan at:
 http://www.dwdataconcepts.com/DevSup.html

 Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or
 higher
 http://www.appointment10.com

 For a quick overview -
 http://www.appointment10.com/Appt10_Promo/Overview.html



?php
echo date('r', strtotime('-1 week', strtotime('next sunday'))); //
Sun, 17 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next monday'))); //
Mon, 18 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next tuesday'))); //
Tue, 19 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next wednesday'))); //
Wed, 20 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next thursday'))); //
Thu, 14 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next friday'))); //
Fri, 15 Oct 2010 00:00:00 +0100
echo date('r', strtotime('-1 week', strtotime('next saturday'))); //
Sat, 16 Oct 2010 00:00:00 +0100
?

Take 1 week off the next day that they want. If today is the start of
the week, then today will be returned.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread Jonathan Sachs
On Wed, 20 Oct 2010 08:37:55 +0200, php-gene...@garydjones.name (Gary)
wrote:

Better. I can tell you how to solve it:
$a = array('a', 'b','c');
foreach($a as $row){
//you don't have to do anything here
}
unset($row); //  THIS IS KEY!
print_r($a);
foreach($a as $row){
echo br /.$row;
}
print_r($a);

I don't quite I follow this. I'll have to try it when I have time (I
hope later today) to understand what you're proposing.

Unfortunately it won't work in this, for one or two reasons.

The first possible reason is that I'm not referencing the as
variable with an ampersand. If I'd have to add one to fix this
problem, it might cause other problems.

The second (definite) reason is that I can't read the array
destructively (with an unset). The problem occurs in code that is
preparing the array for later read-only use, so that would be
self-defeating!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Weird Behavior

2010-10-20 Thread Don Wieland

Little help please ;)

$CD = 1287583899
$q1s = 1283313600
$q1e = 1291093200
$q2s = 1291179600
$q2e = 1298869200
$q3s = 1298955600
$q3e = 1306814400
$q4s = 1306900800
$q4e = 1314763200

Why does the following not return the value 1 in the  $qCur var

// Current Quarter
if($CD = $q1s  $CD = $q1e) $qCur = 1;
if($CD = $q2s  $CD = $q2e) $qCur = 2;
if($CD = $q3s  $CD = $q3e) $qCur = 3;
if($CD = $q4s  $CD = $q4e) $qCur = 4;

it returns 4

Don Wieland


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Weird Behavior

2010-10-20 Thread Daniel Brown
On Wed, Oct 20, 2010 at 10:35, Don Wieland d...@dwdataconcepts.com wrote:
 Little help please ;)

 $CD = 1287583899
 $q1s = 1283313600
 $q1e = 1291093200
 $q2s = 1291179600
 $q2e = 1298869200
 $q3s = 1298955600
 $q3e = 1306814400
 $q4s = 1306900800
 $q4e = 1314763200

 Why does the following not return the value 1 in the  $qCur var

 // Current Quarter
 if($CD = $q1s  $CD = $q1e) $qCur = 1;
 if($CD = $q2s  $CD = $q2e) $qCur = 2;
 if($CD = $q3s  $CD = $q3e) $qCur = 3;
 if($CD = $q4s  $CD = $q4e) $qCur = 4;

 it returns 4

That will return 1 if you add semicolons to the end of your
variable definition block lines.  Otherwise you'll get an unexpected
T_VARIABLE error.

In fact, I just tested it and it returned 1 as expected.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Weird Behavior

2010-10-20 Thread Alexander Schrijver
On Wed, Oct 20, 2010 at 07:35:26AM -0700, Don Wieland wrote:
 Little help please ;)
 
 $CD = 1287583899
 $q1s = 1283313600
 $q1e = 1291093200
 $q2s = 1291179600
 $q2e = 1298869200
 $q3s = 1298955600
 $q3e = 1306814400
 $q4s = 1306900800
 $q4e = 1314763200
 
 Why does the following not return the value 1 in the  $qCur var
 
 // Current Quarter
 if($CD = $q1s  $CD = $q1e) $qCur = 1;
 if($CD = $q2s  $CD = $q2e) $qCur = 2;
 if($CD = $q3s  $CD = $q3e) $qCur = 3;
 if($CD = $q4s  $CD = $q4e) $qCur = 4;
 
 it returns 4

No, $qCur is set to 1.

You've forgot the semicolons if you're testing with this.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Weird Behavior

2010-10-20 Thread Steven Buehler
it returns 1 for me.  Did you put the simicolon after the values?
$CD = 1287583899;
$q1s = 1283313600;
$q1e = 1291093200;
$q2s = 1291179600;
$q2e = 1298869200;
$q3s = 1298955600;
$q3e = 1306814400;
$q4s = 1306900800;
$q4e = 1314763200;

-Original Message-
From: Don Wieland [mailto:d...@dwdataconcepts.com] 
Sent: Wednesday, October 20, 2010 9:35 AM
To: php-general@lists.php.net
Subject: [PHP] Weird Behavior

Little help please ;)

$CD = 1287583899
$q1s = 1283313600
$q1e = 1291093200
$q2s = 1291179600
$q2e = 1298869200
$q3s = 1298955600
$q3e = 1306814400
$q4s = 1306900800
$q4e = 1314763200

Why does the following not return the value 1 in the  $qCur var

// Current Quarter
if($CD = $q1s  $CD = $q1e) $qCur = 1;
if($CD = $q2s  $CD = $q2e) $qCur = 2;
if($CD = $q3s  $CD = $q3e) $qCur = 3;
if($CD = $q4s  $CD = $q4e) $qCur = 4;

it returns 4

Don Wieland


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Calendar Logic Help

2010-10-20 Thread Floyd Resler
I'm having problems getting my head around some login for a calendar.  
Specifically, the problem is drawing weekly views for events that span multiple 
days.  I've gotten it so that if an event starts in the week being viewed, the 
days draw correctly for the remainder of the week.  However, if the event goes 
into the next week, its start date is now outside my date range and so it 
doesn't display.  I know how to say the logic, I'm not sure how to write it!  
The logic would be: if any date between the start and end dates of the event 
are within the week being displayed, show the event.  I'd like to put the logic 
into my MySQL query so I don't have to get all events from the calendar to see 
what should be displayed.  Any ideas?

Thanks!
Floyd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Calendar Logic Help

2010-10-20 Thread Tommy Pham
 -Original Message-
 From: Floyd Resler [mailto:fres...@adex-intl.com]
 Sent: Wednesday, October 20, 2010 9:17 AM
 To: PHP
 Subject: [PHP] Calendar Logic Help
 
 I'm having problems getting my head around some login for a calendar.
 Specifically, the problem is drawing weekly views for events that span
 multiple days.  I've gotten it so that if an event starts in the week
being
 viewed, the days draw correctly for the remainder of the week.  However,
if
 the event goes into the next week, its start date is now outside my date
 range and so it doesn't display.  I know how to say the logic, I'm not
sure
 how to write it!  The logic would be: if any date between the start and
end
 dates of the event are within the week being displayed, show the event.
I'd
 like to put the logic into my MySQL query so I don't have to get all
events
 from the calendar to see what should be displayed.  Any ideas?
 
 Thanks!
 Floyd
 

It's hard to give you hints without knowing some actual PHP code and SQL
table columns but here goes:

PHP logic: $event['startDate'] = $weekEnd  $event['endDate'] =
$weekStart

Query logic: SELECT * FROM event_table WHERE `start_date` = @weekEnd and
`end_date` = @weekStart

week* is the week being viewed.  You may have to use the DateTime class or
one of the date_* functions to compare the date for the PHP logic.  @ is the
input query parameter.  This assumes you have table columns for the event:
start_date  end_date.  Adjust the query as needed for multi table joins.

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread David Harkness
On Wed, Oct 20, 2010 at 5:00 AM, Tommy Pham tommy...@gmail.com wrote:

 Shouldn't that be $row = null since unset will remove the last value, not
 just removing the variable also, from the array whereas the $row = null
 will
 tell the reference pointer that it doesn't point to a value.


No, that would assign null to the last array element. References allow you
to assign any value--including null--to the container they reference.
Unsetting a reference breaks the reference without affecting whatever it
references.

$x = 5;
$y = $x;
$y = null;
print_r($x);
var_dump($x);

-- NULL

David


Re: [PHP] Calendar Logic Help

2010-10-20 Thread Floyd Resler

On Oct 20, 2010, at 12:47 PM, Tommy Pham wrote:

 -Original Message-
 From: Floyd Resler [mailto:fres...@adex-intl.com]
 Sent: Wednesday, October 20, 2010 9:17 AM
 To: PHP
 Subject: [PHP] Calendar Logic Help
 
 I'm having problems getting my head around some login for a calendar.
 Specifically, the problem is drawing weekly views for events that span
 multiple days.  I've gotten it so that if an event starts in the week
 being
 viewed, the days draw correctly for the remainder of the week.  However,
 if
 the event goes into the next week, its start date is now outside my date
 range and so it doesn't display.  I know how to say the logic, I'm not
 sure
 how to write it!  The logic would be: if any date between the start and
 end
 dates of the event are within the week being displayed, show the event.
 I'd
 like to put the logic into my MySQL query so I don't have to get all
 events
 from the calendar to see what should be displayed.  Any ideas?
 
 Thanks!
 Floyd
 
 
 It's hard to give you hints without knowing some actual PHP code and SQL
 table columns but here goes:
 
 PHP logic: $event['startDate'] = $weekEnd  $event['endDate'] =
 $weekStart
 
 Query logic: SELECT * FROM event_table WHERE `start_date` = @weekEnd and
 `end_date` = @weekStart
 
 week* is the week being viewed.  You may have to use the DateTime class or
 one of the date_* functions to compare the date for the PHP logic.  @ is the
 input query parameter.  This assumes you have table columns for the event:
 start_date  end_date.  Adjust the query as needed for multi table joins.
 
 Regards,
 Tommy
 

That worked perfect! 

Thanks!
Floyd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread Tommy Pham
On Wed, Oct 20, 2010 at 10:44 AM, David Harkness
davi...@highgearmedia.com wrote:
 On Wed, Oct 20, 2010 at 5:00 AM, Tommy Pham tommy...@gmail.com wrote:

 Shouldn't that be $row = null since unset will remove the last value, not
 just removing the variable also, from the array whereas the $row = null
 will
 tell the reference pointer that it doesn't point to a value.

 No, that would assign null to the last array element. References allow you
 to assign any value--including null--to the container they reference.
 Unsetting a reference breaks the reference without affecting whatever it
 references.

     $x = 5;
     $y = $x;
     $y = null;
     print_r($x);
     var_dump($x);

     -- NULL

 David


hmm..  About 8-9 years ago I did a project where I used the reference
in a foreach loop as the OP.  unset not only remove the variable but
also the value in the array.  I tried several methods at that time and
ended up assigning null to get what I wanted without modifying the
array.  I'll have to dig up that project later to see.

Thanks,
Tommy

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] I need some thoughts on code duplication and separation

2010-10-20 Thread Rico Secada
Hi.

I am working on a small system where I am both trying to avoid code
duplication and at the same time I am trying to keep the presentation
logic separated from the application logic.

I am using sessions and are avoiding headers already sent problem by
keeping the HTML out of the application.

For example, I would like to have a common header.php file, but it is
difficult to create this since one file needs to have some specific
Javascript located in the head /head tags, but the other files
doesn't need this.

Another file needs to have a specific onload call in the body tag,
while yet another file also needs to have an onload call, but with
different attributes.

I have been looking around in other systems to see what kinds of
solutions are being used - as inspiration.

I have been thinking about the following solutions:

1. Create only ONE header.php file that contains a lot of conditionals
depending on what file is including it - the output of HTML/Javascript
changes.

I believe this would turn into a very ugly hack. Difficult to maintain.

2. Create a HTML generating class with a set of methods that each
contains an adequate amount of parameters. Each method maintains its
own HTML tag. For example, docType($type) would generate the doctype
specification.

I believe this is a cleaner solution, but the problem with code
duplication isn't avoided.

Some of the presentation logic contains conditionals and the HTML
changes when the conditional changes, hence the header content changes,
but the doctype, html, and head doesn't necessarily change and
they would get duplicated a couple of times in some files.

3. Avoid the problem all together, use output buffering and completely
forget about separation between application and presentation.

I hope I make sense.

Any thoughts on these kinds of problems?

Best regards.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I need some thoughts on code duplication and separation

2010-10-20 Thread David McGlone
On Thu, 2010-10-21 at 04:05 +0200, Rico Secada wrote:
 Hi.
 
 I am working on a small system where I am both trying to avoid code
 duplication and at the same time I am trying to keep the presentation
 logic separated from the application logic.
 
 I am using sessions and are avoiding headers already sent problem by
 keeping the HTML out of the application.
 
 For example, I would like to have a common header.php file, but it is
 difficult to create this since one file needs to have some specific
 Javascript located in the head /head tags, but the other files
 doesn't need this.
 
 Another file needs to have a specific onload call in the body tag,
 while yet another file also needs to have an onload call, but with
 different attributes.
 
 I have been looking around in other systems to see what kinds of
 solutions are being used - as inspiration.
 
 I have been thinking about the following solutions:
 
 1. Create only ONE header.php file that contains a lot of conditionals
 depending on what file is including it - the output of HTML/Javascript
 changes.
 
 I believe this would turn into a very ugly hack. Difficult to maintain.
 
 2. Create a HTML generating class with a set of methods that each
 contains an adequate amount of parameters. Each method maintains its
 own HTML tag. For example, docType($type) would generate the doctype
 specification.
 
 I believe this is a cleaner solution, but the problem with code
 duplication isn't avoided.
 
 Some of the presentation logic contains conditionals and the HTML
 changes when the conditional changes, hence the header content changes,
 but the doctype, html, and head doesn't necessarily change and
 they would get duplicated a couple of times in some files.
 
 3. Avoid the problem all together, use output buffering and completely
 forget about separation between application and presentation.
 
 I hope I make sense.
 
 Any thoughts on these kinds of problems?

sounds like a job for smarty http://www.smarty.net/

I've used smarty and it's nice.

-- 
Blessings
David M.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] I need some thoughts on code duplication and separation

2010-10-20 Thread Tommy Pham
 -Original Message-
 From: David McGlone [mailto:da...@dmcentral.net]
 Sent: Wednesday, October 20, 2010 7:59 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] I need some thoughts on code duplication and separation
 
 On Thu, 2010-10-21 at 04:05 +0200, Rico Secada wrote:
  Hi.
 
  I am working on a small system where I am both trying to avoid code
  duplication and at the same time I am trying to keep the presentation
  logic separated from the application logic.
 
  I am using sessions and are avoiding headers already sent problem by
  keeping the HTML out of the application.
 
  For example, I would like to have a common header.php file, but it is
  difficult to create this since one file needs to have some specific
  Javascript located in the head /head tags, but the other files
  doesn't need this.
 
  Another file needs to have a specific onload call in the body tag,
  while yet another file also needs to have an onload call, but with
  different attributes.
 
  I have been looking around in other systems to see what kinds of
  solutions are being used - as inspiration.
 
  I have been thinking about the following solutions:
 
  1. Create only ONE header.php file that contains a lot of conditionals
  depending on what file is including it - the output of HTML/Javascript
  changes.
 
  I believe this would turn into a very ugly hack. Difficult to maintain.
 
  2. Create a HTML generating class with a set of methods that each
  contains an adequate amount of parameters. Each method maintains its
  own HTML tag. For example, docType($type) would generate the doctype
  specification.
 
  I believe this is a cleaner solution, but the problem with code
  duplication isn't avoided.
 
  Some of the presentation logic contains conditionals and the HTML
  changes when the conditional changes, hence the header content
  changes, but the doctype, html, and head doesn't necessarily
  change and they would get duplicated a couple of times in some files.
 
  3. Avoid the problem all together, use output buffering and completely
  forget about separation between application and presentation.
 
  I hope I make sense.
 
  Any thoughts on these kinds of problems?
 
 sounds like a job for smarty http://www.smarty.net/
 
 I've used smarty and it's nice.
 
 --
 Blessings
 David M.
 
 

Thanks David!  I was looking for something like that too!

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php