[PHP] Re: strtotime

2010-10-16 Thread John Taylor-Johnston

According to this, I'm 44 not 45 :)p

$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

  function birthday ($birthday){
list($year,$month,$day) = explode("-",$birthday);
$year_diff  = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff   = date("d") - $day;
if ($day_diff < 0 || $month_diff < 0)
  $year_diff--;
return $year_diff;
  }

echo birthday ($birthday);



John Taylor-Johnston wrote:
I'm working my way right now through the manual: 
http://ca.php.net/manual/en/function.strtotime.php.





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



[PHP] strtotime

2010-10-16 Thread John Taylor-Johnston

$now=date("Y-m-d");

A = $mydata->birthday = 1928-02-12;
B = $mydata->birthday = 1965-03-18;
C = $mydata->birthday = 1976-04-11;

I'm doing a demographic sort.

How do I calculate whether $mydata->Birthday falls into these categories 
below?
I'm working my way right now through the manual: 
http://ca.php.net/manual/en/function.strtotime.php.


I cannot just calculate:
$mydata->birthday - $now  = X age bracket.


80+ year category |  A  |
70+ year category
60+ year category
50+ year category
40+ year category |  B  |
30+ year category |  C  |
21+ year category

Thans for any inspiration. I can find and hack code. I'm just like to 
understand it myself.


John

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



RE: [PHP] Questions from a Newbie

2010-10-16 Thread Tommy Pham
> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: Saturday, October 16, 2010 10:01 PM
> To: php-general@lists.php.net
> Subject: [PHP] Questions from a Newbie
> 
> Dear List -
> 
> Here are some questions, which I am sure are trivial, but I am a newbie,
and
> cannot find the answers online
> 
> I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
> enter the following URL: [w/ the http]
> 
>   localhost/CreateNew.php All I get is a blank browser screen.
> 
> The code  contained in the file CreateNew.php is:
> 
> /*
>   *  Create Database test22
>   */
>   
>  $cxn = mysqli_connect("$host",$user,$password);
> echo"Create database test22;"
> echo"Create table Names2
> (
>  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
>  FirstName varchar(10),
>  LastName varchar(10),
>  Height  decimal(4,1),
>  Weight0 decimal(4,1),
>  BMI decimal(3,1)
>  Date0 date
> );"
> 
> echo"   Create table Visit2
> (
>  Indx Int(7) Primary Key Not null auto_increment,
>  Weight decimal(4,1) not null,
>  StudyDate date not null,
>  RecordNum Int(11)
> );"
> 
>  $sql= "SHOW DATABASES";
> ?>
> 
> 
> If I search for test22 or Visit2, nothing is found.
> 
> I would also like to be able to add data to a table, using PHP, which I
can do
> in MySQL as:
> load data infile '/home/ethan/Databases/tester21.dat.' replace into table
> Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
> 
> Thanks in advance.
> 
> Ethan
> ===
> Using Debian(sid)
> 

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php



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



[PHP] Questions from a Newbie

2010-10-16 Thread Ethan Rosenberg

Dear List -

Here are some questions, which I am sure are trivial, but I am a 
newbie, and cannot find the answers online


I cannot get the following to work.  In my Firefox [Iceweasel] 
browser, I enter the following URL: [w/ the http]


 localhost/CreateNew.php All I get is a blank browser screen.

The code  contained in the file CreateNew.php is:

/*
 *  Create Database test22
 */
 



If I search for test22 or Visit2, nothing is found.

I would also like to be able to add data to a table, using PHP, which 
I can do in MySQL as:
load data infile '/home/ethan/Databases/tester21.dat.' replace into 
table Names fields escaped by '\\' terminated by '\t'  lines 
terminated by '\n' ;


Thanks in advance.

Ethan
===
Using Debian(sid)  




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



[PHP] Addendum: Binary data unpacking

2010-10-16 Thread Justin Martin

Sorry, I had forgotten that attachments weren't accepted on the list.

My code can be found at http://pastebin.com/6nmR67c3.

The test NBT can be found via the NBT specification link.

Thanks,
Justin Martin

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



[PHP] Binary data unpacking

2010-10-16 Thread Justin Martin

Hello everyone,

For the past while, I've been working on a class for reading in, 
modifying and writing out NBT-format files. This particular format is 
used for the game Minecraft, as some of you may know.


Attached is my work so far on this, which is coming close to being a 
working solution to reading the files in. As well, attached is an 
example NBT for testing the script.


The specification for the NBT format can be found at 
http://www.minecraft.net/docs/NBT.txt.


The issue which I'm having is that PHP's pack and unpack function for 
binary data does not seem to be complete. Or, at least, it's missing 
certain functionality which is necessary for what I'm trying to do.


It may be a matter of misunderstanding on my part, but I would have 
expected the pack and unpack function to be able to handle every 
combination of endianness, signing and machine-specific sizing of each type.


Currently, I'm stuck in reading in the TAG_INT type of the NBT format, 
which is a 32-bit signed short, big-endian, as per the specification. 
There does not seem to be a packing format code for this data type.


How might I go about this? Am I simply missing something about binary 
data, or is PHP's pack/unpack functionality indeed lacking? And, if the 
pack and unpack functions are indeed lacking, is it possible to handle 
binary data without those functions?


Thanks,
Justin Martin
<>
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] Error message not understood

2010-10-16 Thread Tommy Pham
> -Original Message-
> From: sueandant [mailto:hollandsath...@tiscali.co.uk]
> Sent: Saturday, October 16, 2010 2:23 PM
> To: Tommy Pham
> Cc: PHP
> Subject: Re: [PHP] Error message not understood
> 
> Apologies!   Vista Home Premium 32bit with SP2.   I uninstalled it using
> Windows' uninstaller.   I didn't compile any of the packages.   MySQL was
> installed using the .msi download and PHP I simply unzipped to my C:\PHP
> folder.   And, yes, they both came from the official sites.
> 

Forgot to mention something, please don't top post.  It makes hard for
others to follow the thread.

Are you running PHP with IIS or Apache?  If with Apache how are you running
PHP as, CGI or module?  Since you're using official distributions, you'll
have to use PHP VC6 TS build (if not using as CGI/FastCGI) for Apache [1].
If you're running PHP with IIS, you'll have to run NTS build for FastCGI
[2].

[1] http://windows.php.net/downloads/releases/php-5.3.3-Win32-VC6-x86.zip
[2]
http://windows.php.net/downloads/releases/php-5.3.3-nts-Win32-VC9-x86.zip

> - Original Message -
> From: "Tommy Pham" 
> To: "'sueandant'" ; "'Luigi Pressello'"
> 
> Cc: "'PHP'" 
> Sent: Saturday, October 16, 2010 9:38 PM
> Subject: RE: [PHP] Error message not understood
> 
> 
> >> -Original Message-
> >> From: sueandant [mailto:hollandsath...@tiscali.co.uk]
> >> Sent: Saturday, October 16, 2010 1:16 PM
> >> To: Luigi Pressello
> >> Cc: PHP
> >> Subject: Re: [PHP] Error message not understood
> >>
> >> I've run both programs. [1] outputs Client library version 5.1.51, but
> >> [2]
> >> gives no output.   However I have checked MySql status via the command
> >> prompt which tells me mysql Ver 14.14 Distrib 5.1.51 for Win32(ia32).
> >
> > You still haven't answer the question of what platform? FreeBSD? Linux?
> > Mac?
> > Windows?  And what is the platform version?
> >
> >>
> >> I originally installed PHP 5.3 but I couldn't get it to communicate
with
> > mysqli
> >> (and I tried everything!) so I unstalled it and replaced it with
> >
> > How did you uninstall?  Using the OS's software/package manager such
> > package
> > on FreeBSD, yast on some Linux, add/remove programs on Windows, etc.?
> Did
> > you compile any of it - MySQL or PHP - yourself?
> >
> >> version 5.2.14.   PHP info tells me this that the Client API library
> > version
> >> is 5.1.51 and the header version is 5.0.51a.
> >
> > This just means that there's a mismatch within the PHP.  If you compiled
> > from source for any of it, PHP's MySQL & MySQLi extensions depends on
> the
> > MySQL headers and client library.  Thus, MySQL client has to be compiled
> > first before you can compile the PHP's MySQL/MySQLi extensions.  This
> > applies to all platforms if you're doing your compilation from source.
If
> > you didn't compile any of it - both MySQL and PHP - then the problem
lies
> > within your OS's software/package manager.  Without knowing what
> you're
> > using, we can't really tell what happens.  Some Linux distributions do
> > things differently.  I'm not well versed in Linux but many others here
on
> > this list can help you with it.  I suggest you 'uninstall' both PHP &
> > MySQL.
> > Then reinstall MySQL 1st and PHP 2nd.  Also, just a bit curious... where
> > did
> > you get the MySQL & PHP?  I hope directly from the official source... ;)
> >
> >>
> >> Does this help identify a solution?
> >>
> >> Thanks and best wishes
> >>
> >> tholland
> >
> > 
> >
> > Regards,
> > Tommy
> >
> >
> > --
> > 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



Re: [PHP] Error message not understood

2010-10-16 Thread sueandant
Apologies!   Vista Home Premium 32bit with SP2.   I uninstalled it using 
Windows' uninstaller.   I didn't compile any of the packages.   MySQL was 
installed using the .msi download and PHP I simply unzipped to my C:\PHP 
folder.   And, yes, they both came from the official sites.


- Original Message - 
From: "Tommy Pham" 
To: "'sueandant'" ; "'Luigi Pressello'" 


Cc: "'PHP'" 
Sent: Saturday, October 16, 2010 9:38 PM
Subject: RE: [PHP] Error message not understood



-Original Message-
From: sueandant [mailto:hollandsath...@tiscali.co.uk]
Sent: Saturday, October 16, 2010 1:16 PM
To: Luigi Pressello
Cc: PHP
Subject: Re: [PHP] Error message not understood

I've run both programs. [1] outputs Client library version 5.1.51, but 
[2]

gives no output.   However I have checked MySql status via the command
prompt which tells me mysql Ver 14.14 Distrib 5.1.51 for Win32(ia32).


You still haven't answer the question of what platform? FreeBSD? Linux? 
Mac?

Windows?  And what is the platform version?



I originally installed PHP 5.3 but I couldn't get it to communicate with

mysqli

(and I tried everything!) so I unstalled it and replaced it with


How did you uninstall?  Using the OS's software/package manager such 
package

on FreeBSD, yast on some Linux, add/remove programs on Windows, etc.?  Did
you compile any of it - MySQL or PHP - yourself?


version 5.2.14.   PHP info tells me this that the Client API library

version

is 5.1.51 and the header version is 5.0.51a.


This just means that there's a mismatch within the PHP.  If you compiled
from source for any of it, PHP's MySQL & MySQLi extensions depends on the
MySQL headers and client library.  Thus, MySQL client has to be compiled
first before you can compile the PHP's MySQL/MySQLi extensions.  This
applies to all platforms if you're doing your compilation from source.  If
you didn't compile any of it - both MySQL and PHP - then the problem lies
within your OS's software/package manager.  Without knowing what you're
using, we can't really tell what happens.  Some Linux distributions do
things differently.  I'm not well versed in Linux but many others here on
this list can help you with it.  I suggest you 'uninstall' both PHP & 
MySQL.
Then reinstall MySQL 1st and PHP 2nd.  Also, just a bit curious... where 
did

you get the MySQL & PHP?  I hope directly from the official source... ;)



Does this help identify a solution?

Thanks and best wishes

tholland




Regards,
Tommy


--
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



RE: [PHP] Error message not understood

2010-10-16 Thread Tommy Pham
> -Original Message-
> From: sueandant [mailto:hollandsath...@tiscali.co.uk]
> Sent: Saturday, October 16, 2010 1:16 PM
> To: Luigi Pressello
> Cc: PHP
> Subject: Re: [PHP] Error message not understood
> 
> I've run both programs. [1] outputs Client library version 5.1.51, but [2]
> gives no output.   However I have checked MySql status via the command
> prompt which tells me mysql Ver 14.14 Distrib 5.1.51 for Win32(ia32).

You still haven't answer the question of what platform? FreeBSD? Linux? Mac?
Windows?  And what is the platform version?

> 
> I originally installed PHP 5.3 but I couldn't get it to communicate with
mysqli
> (and I tried everything!) so I unstalled it and replaced it with

How did you uninstall?  Using the OS's software/package manager such package
on FreeBSD, yast on some Linux, add/remove programs on Windows, etc.?  Did
you compile any of it - MySQL or PHP - yourself?

> version 5.2.14.   PHP info tells me this that the Client API library
version
> is 5.1.51 and the header version is 5.0.51a.

This just means that there's a mismatch within the PHP.  If you compiled
from source for any of it, PHP's MySQL & MySQLi extensions depends on the
MySQL headers and client library.  Thus, MySQL client has to be compiled
first before you can compile the PHP's MySQL/MySQLi extensions.  This
applies to all platforms if you're doing your compilation from source.  If
you didn't compile any of it - both MySQL and PHP - then the problem lies
within your OS's software/package manager.  Without knowing what you're
using, we can't really tell what happens.  Some Linux distributions do
things differently.  I'm not well versed in Linux but many others here on
this list can help you with it.  I suggest you 'uninstall' both PHP & MySQL.
Then reinstall MySQL 1st and PHP 2nd.  Also, just a bit curious... where did
you get the MySQL & PHP?  I hope directly from the official source... ;)

> 
> Does this help identify a solution?
> 
> Thanks and best wishes
> 
> tholland



Regards,
Tommy


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



Re: [PHP] Error message not understood

2010-10-16 Thread sueandant
I've run both programs. [1] outputs Client library version 5.1.51, but [2] 
gives no output.   However I have checked MySql status via the command 
prompt which tells me mysql Ver 14.14 Distrib 5.1.51 for Win32(ia32).


I originally installed PHP 5.3 but I couldn't get it to communicate with 
mysqli (and I tried everything!) so I unstalled it and replaced it with 
version 5.2.14.   PHP info tells me this that the Client API library version 
is 5.1.51 and the header version is 5.0.51a.


Does this help identify a solution?

Thanks and best wishes

tholland
- Original Message - 
From: "Luigi Pressello" 

To: "Tommy Pham" 
Cc: "'sueandant'" ; "'PHP'" 


Sent: Friday, October 15, 2010 10:46 PM
Subject: Re: [PHP] Error message not understood


Probably a PHP compilation problem.
The message seems refer to the headers (libmysql.h) used in the ./configure 
phase of the building process.


It seems like your PHP version was compiled using a MySQL 5.0.11 version 
header, while your connecting to a server running MySQL 5.1.51, Have you 
upgraded your MySQL recently? are you using the MySQL server on the same 
machine that runs Apache/IIS/etc.. and PHP?


Sorry for the "Italianese" english :)

Luigi.

Il giorno 15/ott/2010, alle ore 23.19, Tommy Pham ha scritto:


-Original Message-
From: Tommy Pham [mailto:tommy...@gmail.com]
Sent: Friday, October 15, 2010 2:16 PM
To: 'sueandant'; 'PHP'
Subject: RE: [PHP] Error message not understood


-Original Message-
From: sueandant [mailto:hollandsath...@tiscali.co.uk]
Sent: Friday, October 15, 2010 2:02 PM
To: PHP
Subject: [PHP] Error message not understood

Can anyone help me with this error message and explain how to correct
the mismatch?

PHP Warning:  mysqli_connect() [function.mysqli-connect]: Headers and client library
minor version mismatch. Headers:50051 Library:50151

tholland


It would help if you provide the platform and platform version:
Windows, Linux, Mac, FreeBSD, or other variants.

And also the PHP version you're using.  Did you compile PHP yourself or

use

a distribution?

Regards,
Tommy


Forgot to mention this earlier... too hasty on the send button ... lol.

Since it's only a warning and you are able to connect, run [1] & [2] to 
see

what do you get.

[1] http://us2.php.net/manual/en/mysqli.get-client-info.php
[2] http://us2.php.net/manual/en/mysqli.info.php



--
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



Re: [PHP] odd while behavior...

2010-10-16 Thread a...@ashleysheridan.co.uk
I wouldn't really use a while statement for this, but a for loop instead, as it 
needs less code:

";

for($i =1;$i<=12;$i++)
{
     $dateformat = date("M", mktime(0,0,0, $i,0,0));

     echo <<$dateformat $i

HTML;
}

echo "";
?>


The other code was starting from 0 and going to 12, which is 13 months! Also, 
you had the variable being compared as a string, which will work in this 
particular case, because php will convert $i to a string before each comparison 
in the loop. While it works in this case, its best practice to use the variable 
type you need to avoid unusual behavior.

The mktime function is unusual in that indexes for months start at 1 and not 0 
as you might expect, but it does indicate that on the manual pages.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: "Jason Pruim" 
Date: Sat, Oct 16, 2010 16:12
Subject: [PHP] odd while behavior...
To: "PHP General list" 

Okay so I'm just playing around with some stuff trying to learn more  
and expand my knowledge and I ran into something I don't understand...  
Take the following code:

";
$i ="0";
 while($i <="12") {

 $dateformat = date("M", mktime(0,0,0, $i,0,0));
 $month = mktime(0,0,0, $i,0,0);
 //echo date("M", mktime(0,0,0, $i,0,0));
 //echo "inside while";
 echo <<{$dateformat} {$i}
HTML;
 $i++;
 }
echo "";

?>

which does display a select drop down box with the month's in it...  
But on my test server it starts the display at december... With  
setting $i = "1" i would have thought it should start at january?

Any ideas on what I missed? :)


Thanks for looking! :)


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



Re: [PHP] odd while behavior...

2010-10-16 Thread Alexander Schrijver
On Sat, Oct 16, 2010 at 11:12:03AM -0400, Jason Pruim wrote:
> Okay so I'm just playing around with some stuff trying to learn more
> and expand my knowledge and I ran into something I don't
> understand... Take the following code:
> 
>  
> echo "";
> $i ="0";
> while($i <="12") {
> 
> $dateformat = date("M", mktime(0,0,0, $i,0,0));
> $month = mktime(0,0,0, $i,0,0);
> //echo date("M", mktime(0,0,0, $i,0,0));
> //echo "inside while";
> echo << {$dateformat} {$i}
> HTML;
> $i++;
> }
> echo "";
> 
> ?>
> 
> which does display a select drop down box with the month's in it...
> But on my test server it starts the display at december... With
> setting $i = "1" i would have thought it should start at january?
> 
> Any ideas on what I missed? :)
> 
> 
> Thanks for looking! :)
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

You'r specifying day 0. Which actually is in december. It is an optional
argument. So you can specifify mktime(0,0,0,$1) instead.

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



Re: [PHP] odd while behavior...

2010-10-16 Thread Simon J Welsh
This is because of your mktime() call. You're trying to get the zeroth day of 
the month, which is the last day of the preceding month. Using mktime(0, 0, 0, 
$i, 1) instead should give you the desired results, assuming you do start at 1, 
and not 0 as you have in your code.
---
Simon Welsh

On 17/10/2010, at 4:12, Jason Pruim  wrote:

> Okay so I'm just playing around with some stuff trying to learn more and 
> expand my knowledge and I ran into something I don't understand... Take the 
> following code:
> 
>  
> echo "";
> $i ="0";
>while($i <="12") {
> 
>$dateformat = date("M", mktime(0,0,0, $i,0,0));
>$month = mktime(0,0,0, $i,0,0);
>//echo date("M", mktime(0,0,0, $i,0,0));
>//echo "inside while";
>echo <<{$dateformat} {$i}
> HTML;
>$i++;
>}
> echo "";
> 
> ?>
> 
> which does display a select drop down box with the month's in it... But on my 
> test server it starts the display at december... With setting $i = "1" i 
> would have thought it should start at january?
> 
> Any ideas on what I missed? :)
> 
> 
> Thanks for looking! :)
> 
> 
> -- 
> 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] odd while behavior...

2010-10-16 Thread Jason Pruim
Okay so I'm just playing around with some stuff trying to learn more  
and expand my knowledge and I ran into something I don't understand...  
Take the following code:


";
$i ="0";
while($i <="12") {

$dateformat = date("M", mktime(0,0,0, $i,0,0));
$month = mktime(0,0,0, $i,0,0);
//echo date("M", mktime(0,0,0, $i,0,0));
//echo "inside while";
echo <<{$dateformat} {$i}
HTML;
$i++;
}
echo "";

?>

which does display a select drop down box with the month's in it...  
But on my test server it starts the display at december... With  
setting $i = "1" i would have thought it should start at january?


Any ideas on what I missed? :)


Thanks for looking! :)


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