php-general Digest 17 Oct 2010 18:23:07 -0000 Issue 6992
Topics (messages 308757 through 308767):
Re: Questions from a Newbie
308757 by: Tommy Pham
308760 by: Christian Heinrich
308761 by: Alexis
308762 by: Tommy Pham
308767 by: Ethan Rosenberg
strtotime
308758 by: John Taylor-Johnston
308759 by: John Taylor-Johnston
308764 by: Tamara Temple
308765 by: Tommy Pham
About Character Set
308763 by: ФêÏ
308766 by: Ashley Sheridan
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
> -----Original Message-----
> From: Ethan Rosenberg [mailto:[email protected]]
> Sent: Saturday, October 16, 2010 10:01 PM
> To: [email protected]
> 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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
> echo "Create database test22;"
> echo "Create table Names2
> (
> RecordNum Int(11) Primary Key Not null default=10000
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";
> ?>
> </body></html>
>
> 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
--- End Message ---
--- Begin Message ---
Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb 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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
> echo "Create database test22;"
> echo "Create table Names2
> (
> RecordNum Int(11) Primary Key Not null default=10000 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";
> ?>
> </body></html>
>
> 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)
>
>
>
Hi,
maybe you also want to take a look at PDO - http://php.net/pdo
Regards
Christian
--- End Message ---
--- Begin Message ---
Ethan,you have the end of line semi colons enclosed in double
quotes..move them to the true end of line.
On 17/10/10 04:45, Christian Heinrich wrote:
Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb 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
*/
<html><body>
<?php
$cxn = mysqli_connect("$host",$user,$password);
echo "Create database test22;"
echo "Create table Names2
(
RecordNum Int(11) Primary Key Not null default=10000 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";
?>
</body></html>
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)
Hi,
maybe you also want to take a look at PDO - http://php.net/pdo
Regards
Christian
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Alexis [mailto:[email protected]]
> Sent: Sunday, October 17, 2010 4:10 AM
> To: [email protected]
> Subject: Re: [PHP] Questions from a Newbie
>
> Ethan,you have the end of line semi colons enclosed in double
> quotes..move them to the true end of line.
>
Even if he does move the semicolons to outside the quote, it doesn't do what he
intended as maintaining the database. His code merely echo the SQL syntax for
viewing and not actually executing the SQL syntax, which is what I think he
intended. In which case, he's better off using phpMyAdmin.
Regards,
Tommy
> On 17/10/10 04:45, Christian Heinrich wrote:
> > Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb 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
> >> */
> >> <html><body>
> >> <?php
> >> $cxn = mysqli_connect("$host",$user,$password);
> >> echo "Create database test22;"
> >> echo "Create table Names2
> >> (
> >> RecordNum Int(11) Primary Key Not null default=10000
> 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";
> >> ?>
> >> </body></html>
> >>
> >> 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)
> >>
> >>
> >>
> >
> >
> > Hi,
> >
> > maybe you also want to take a look at PDO - http://php.net/pdo
> >
> > Regards
> > Christian
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
At 01:41 AM 10/17/2010, Tommy Pham wrote:
> -----Original Message-----
> From: Ethan Rosenberg [mailto:[email protected]]
> Sent: Saturday, October 16, 2010 10:01 PM
> To: [email protected]
> 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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
> echo "Create database test22;"
> echo "Create table Names2
> (
> RecordNum Int(11) Primary Key Not null default=10000
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";
> ?>
> </body></html>
>
> 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
Tommy -
Thanks.
As I stated, I am a newbie.
1] I am trying to shorten the learning curve by asking some
questions, which I understand are probably trivial. A whole MySQLi
list of functions at this point is to much for me. I have to break
the problem into manageable parts.
2] It has been my experience that using a GUI does not teach the
whole subject. Linux, which is the OS I use cannot be run from a GUI.
In the code being discussed, I wish to create a database and add two
tables. I also note a MySQL statement that can be used to add data
to an existing table, and wish to be able to execute this statement
using PHP.
So, therefore......
Let us try to answer the following two(2) questions:
a] What changes [other than moving the simicolons] have to be made to
correct the code.
b] What books can you suggest to help w/ MySQL and PHP? I already
have the SQL, MySQL & PHP, and HTML books in the ..... for Dummies
series. I need something with a little more depth and detail.
Thanks to all for your excellent help.
Ethan
========
Using Debian(sid)
++++++++
--- End Message ---
--- Begin Message ---
$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
--- End Message ---
--- Begin Message ---
According to this, I'm 44 not 45 :)p
$birthday = '1965-08-30';
//calculate years of age (input string: YYYY-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.
--- End Message ---
--- Begin Message ---
On Oct 17, 2010, at 12:58 AM, John Taylor-Johnston wrote:
According to this, I'm 44 not 45 :)p
$birthday = '1965-08-30';
//calculate years of age (input string: YYYY-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)
This will trigger anytime the current day of the month is less than 30.
$year_diff--;
return $year_diff;
}
echo birthday ($birthday);
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: John Taylor-Johnston [mailto:John.Taylor-
> [email protected]]
> Sent: Saturday, October 16, 2010 10:58 PM
> To: PHP-General
> Subject: [PHP] Re: strtotime
>
> According to this, I'm 44 not 45 :)p
>
> $birthday = '1965-08-30';
>
> //calculate years of age (input string: YYYY-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)
I think the problem is with the logic above.
$year_diff = 44
$month_diff = 2
$day_diff = -13
Since the $month_diff is positive meaning you're already passed your
birthdate. If the $month_diff is 0 - your birth month, then you need to
check if the if it's past your birth day yet (negative $day_diff).
That logic should be changed to if if (($month_diff == 0 && $day_diff < 0)
|| $month_diff < 0)
Then you're 45 ;)
Regards,
Tommy
> $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.
> >
> >
--- End Message ---
--- Begin Message ---
There is a "download" directory(to provide download links) in my site.
http://vedaclub.org/download/
Some of the filenames contain Chinese characters, which, however cannot be
recognized.
Is there anything I can do to solve problem?
Thanks in advance!
--- End Message ---
--- Begin Message ---
On Sun, 2010-10-17 at 21:56 +0800, 肖晗 wrote:
> There is a "download" directory(to provide download links) in my site.
> http://vedaclub.org/download/
> Some of the filenames contain Chinese characters, which, however cannot be
> recognized.
> Is there anything I can do to solve problem?
>
> Thanks in advance!
The short answer is "yes, remove the Chinese characters", however, I
think you were looking for something a little more automatic?
If the URL itself is causing the problem, maybe you could use the
urlencode() and urldecode() functions to make the filename for the URL
web-safe.
Another alternative that I've used before is to give each file an entry
in a DB and use a moniker to identify the file. The DB can handle all
sorts of extra functions in the future, such as allowing only specific
users to access a file, storing multiple versions of the same file
bearing the same name (on the server each version has a unique name, the
user need only know that they're requesting template.doc, version 3,
etc) and many other things.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---