php-general Digest 28 Jul 2009 15:25:54 -0000 Issue 6254

Topics (messages 295907 through 295939):

Re: newbie: problem with $_Post[]
        295907 by: Bastien Koert
        295908 by: Richard S. Crawford
        295909 by: Paul M Foster
        295911 by: A.a.k

Re: Single Quotes in Form Inputs
        295910 by: Ben Dunlap
        295912 by: Michael A. Peters

Font problem
        295913 by: Dušan Novaković
        295914 by: Ashley Sheridan
        295924 by: Richard S. Crawford

Re: Correct code ?? PHP Basic pw athentication with mysql
        295915 by: WebPat

Making several variables into 1 variable
        295916 by: Miller, Terion
        295917 by: Ashley Sheridan
        295918 by: João Cândido de Souza Neto
        295919 by: Richard S. Crawford
        295920 by: Miller, Terion
        295921 by: Bob McConnell
        295922 by: Ashley Sheridan
        295923 by: Miller, Terion
        295925 by: Ashley Sheridan
        295926 by: Miller, Terion
        295927 by: Ashley Sheridan
        295928 by: Bastien Koert
        295929 by: Miller, Terion
        295930 by: Ian
        295931 by: Floyd Resler
        295934 by: Carlos Medina
        295935 by: Bob McConnell
        295936 by: Miller, Terion
        295937 by: Bastien Koert
        295938 by: Miller, Terion
        295939 by: Bastien Koert

Multiple MySQL Queries
        295932 by: sono-io.fannullone.us
        295933 by: Bastien Koert

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


----------------------------------------------------------------------
--- Begin Message ---
On Mon, Jul 27, 2009 at 10:31 PM, A.a.k<blue...@gmail.com> wrote:
> Hello
> I have a very simple test form named "pass.php"  :
>
> <form action="pass.php" method=POST>
> username : <input type=text name=user ><br />
> password : <input type=password name=pass> <br />
> <input type=submit value="go"><p>
> </form>
>
> <?php
> $user=$_POST['user'];
> $pass=$_POST['pass'];
> if(($user=="myname")&&($pass="mypass"))
> echo "access granted";
> else
> echo "access denied";
> ?>
>
> getting "Notice: Undefined index: user" and "Notice: Undefined index: pass".
> changing form action to another page will solve the problem but i want to be
> able to use $_POST array on the same page, how can i do it?
> thanks in advance
>
> /Arash
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Define them

$user='';
$pass='';

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
>> <form action="pass.php" method=POST>
>> username : <input type=text name=user ><br />
>> password : <input type=password name=pass> <br />
>> <input type=submit value="go"><p>
>> </form>
>>
>> <?php
>> $user=$_POST['user'];
>> $pass=$_POST['pass'];
>> if(($user=="myname")&&($pass="mypass"))
>> echo "access granted";
>> else
>> echo "access denied";
>> ?>
>>
>> getting "Notice: Undefined index: user" and "Notice: Undefined index: pass".
>> changing form action to another page will solve the problem but i want to be
>> able to use $_POST array on the same page, how can i do it?
>> thanks in advance
>>
>> /Arash

Arash,

It's hard to respond when it's unclear exactly what you want to do.
I'm guessing that you want to simply have the same page show both the
form, and also process the form, so that you can cut down on the
number of pages you have to create.

The way I do this is by first checking to see if the $_POST array has
been set; if it has not been set, then I know that the form wasn't
filled out, and so the script needs to print out the form. If the
array has been set, on the other hand, then the script can process the
form data. Here's a real quick example of what I mean:

<?php
if (!isset($_POST)) { ?> // The $_POST array is not set, so display the form
    <form action="pass.php" method=POST>
    username : <input type="text" name="user" ><br />
    password : <input type="password" name="pass"> <br />
    <input type="submit" value="go"><p>
    </form>
<?php } else { // The $_POST array *is* set, so process the data
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    if(($user=="myname")&&($pass="mypass")) {
    echo "access granted";
    } else {
    echo "access denied";
    }
?>

Hope that helps.

--
Richard S. Crawford (rscrawf...@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message ---
On Mon, Jul 27, 2009 at 09:01:16PM -0700, Richard S. Crawford wrote:

> >> <form action="pass.php" method=POST>
> >> username : <input type=text name=user ><br />
> >> password : <input type=password name=pass> <br />
> >> <input type=submit value="go"><p>
> >> </form>
> >>
> >> <?php
> >> $user=$_POST['user'];
> >> $pass=$_POST['pass'];
> >> if(($user=="myname")&&($pass="mypass"))
> >> echo "access granted";
> >> else
> >> echo "access denied";
> >> ?>
> >>
> >> getting "Notice: Undefined index: user" and "Notice: Undefined index: 
> >> pass".
> >> changing form action to another page will solve the problem but i want to 
> >> be
> >> able to use $_POST array on the same page, how can i do it?
> >> thanks in advance
> >>
> >> /Arash
> 
> Arash,
> 
> It's hard to respond when it's unclear exactly what you want to do.
> I'm guessing that you want to simply have the same page show both the
> form, and also process the form, so that you can cut down on the
> number of pages you have to create.
> 
> The way I do this is by first checking to see if the $_POST array has
> been set; if it has not been set, then I know that the form wasn't
> filled out, and so the script needs to print out the form. If the
> array has been set, on the other hand, then the script can process the
> form data. Here's a real quick example of what I mean:
> 
> <?php
> if (!isset($_POST)) { ?> // The $_POST array is not set, so display the form
>     <form action="pass.php" method=POST>
>     username : <input type="text" name="user" ><br />
>     password : <input type="password" name="pass"> <br />
>     <input type="submit" value="go"><p>
>     </form>
> <?php } else { // The $_POST array *is* set, so process the data
>     $user=$_POST['user'];
>     $pass=$_POST['pass'];
>     if(($user=="myname")&&($pass="mypass")) {
>     echo "access granted";
>     } else {
>     echo "access denied";
>     }
> ?>
> 
> Hope that helps.

Richard's right. This is the best way to do this.

Your original code had two problems. First, you're getting the error
message because you're allowing E_NOTICE level error messages. You can
turn these off with the error_reporting() function.

Second, as written, your page paints the form and then directly tests
the status of the variables before the user can respond; the whole page
of PHP code executes and then waits for user response. It's only when
the user responds and the page is revisited that the variables can
legitimately be tested. That's why Richard's method works. The
variables are only tested when the page is re-entered after the user
responds.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
Hello
Richard, that is exactly what I was looking for. thanks alot
Paul, I didn't know its possible to use error_reporting(), that's a good hint thanks. btw if you guys know any simple php application that I can study and learn faster than going through books please let me know. I tried Wordpress but its too complicated for a beginner like me.


"Paul M Foster" <pa...@quillandmouse.com> wrote in message news:20090728043523.gs14...@quillandmouse.com...
On Mon, Jul 27, 2009 at 09:01:16PM -0700, Richard S. Crawford wrote:

>> <form action="pass.php" method=POST>
>> username : <input type=text name=user ><br />
>> password : <input type=password name=pass> <br />
>> <input type=submit value="go"><p>
>> </form>
>>
>> <?php
>> $user=$_POST['user'];
>> $pass=$_POST['pass'];
>> if(($user=="myname")&&($pass="mypass"))
>> echo "access granted";
>> else
>> echo "access denied";
>> ?>
>>
>> getting "Notice: Undefined index: user" and "Notice: Undefined index: >> pass". >> changing form action to another page will solve the problem but i want >> to be
>> able to use $_POST array on the same page, how can i do it?
>> thanks in advance
>>
>> /Arash

Arash,

It's hard to respond when it's unclear exactly what you want to do.
I'm guessing that you want to simply have the same page show both the
form, and also process the form, so that you can cut down on the
number of pages you have to create.

The way I do this is by first checking to see if the $_POST array has
been set; if it has not been set, then I know that the form wasn't
filled out, and so the script needs to print out the form. If the
array has been set, on the other hand, then the script can process the
form data. Here's a real quick example of what I mean:

<?php
if (!isset($_POST)) { ?> // The $_POST array is not set, so display the form
<form action="pass.php" method=POST>
username : <input type="text" name="user" ><br />
password : <input type="password" name="pass"> <br />
<input type="submit" value="go"><p>
</form>
<?php } else { // The $_POST array *is* set, so process the data
$user=$_POST['user'];
$pass=$_POST['pass'];
if(($user=="myname")&&($pass="mypass")) {
echo "access granted";
} else {
echo "access denied";
}
?>

Hope that helps.

Richard's right. This is the best way to do this.

Your original code had two problems. First, you're getting the error
message because you're allowing E_NOTICE level error messages. You can
turn these off with the error_reporting() function.

Second, as written, your page paints the form and then directly tests
the status of the variables before the user can respond; the whole page
of PHP code executes and then waits for user response. It's only when
the user responds and the page is revisited that the variables can
legitimately be tested. That's why Richard's method works. The
variables are only tested when the page is re-entered after the user
responds.

Paul

--
Paul M. Foster
--- End Message ---
--- Begin Message ---
 You can use http://us.php.net/mysql_real_escape_string to escape the
input.
[8<]
You should prep your data for insertion into the data by using a tool
that formats it strictly for the database.  In the ops case
mysql_real_escape_string() is the correct tool for the job.

What about using prepared statements? This is my preferred method of "escaping output" when I'm using variables in a database query. Of course the ease and convenience of this method will depend to a great extent on what version of PHP is available on the server.

For the OP, have you read up much on SQL injection? If not, here's a decent place to start: http://www.owasp.org/index.php/SQL_injection

Ben

--- End Message ---
--- Begin Message ---
Ben Dunlap wrote:
 You can use http://us.php.net/mysql_real_escape_string to escape the
input.
[8<]
You should prep your data for insertion into the data by using a tool
that formats it strictly for the database.  In the ops case
mysql_real_escape_string() is the correct tool for the job.

What about using prepared statements? This is my preferred method of "escaping output" when I'm using variables in a database query. Of course the ease and convenience of this method will depend to a great extent on what version of PHP is available on the server.

For the OP, have you read up much on SQL injection? If not, here's a decent place to start: http://www.owasp.org/index.php/SQL_injection

Ben


Prepared statements are what I use.

-=-

The problem I have with htmlentities is that the entities are only guaranteed for html. Many of the entities do not work in other sgml or xml applications, it is better to just use the numbered entity (IE &#160; for a non breaking space) or for things like smart quotes, possessive apostraphe's, etc. - the proper utf8 character directly (make sure to serve document as utf8 encoded and that your database is set to utf8)

I found that out the hard way, and had to redo a lot of stuff where I previously used the php htmlentities function. Using the function to spit out html is fine, but to write functions / classes you can re-use in non html documents, you should avoid it all together.
--- End Message ---
--- Begin Message ---
Hi,

Is there a possibility that if there is no font installed on client
side somehow browser finds it and redirect that font form server to
client machine. For example: I have site that use Microsoft font and
that font is not available on Linux distributions. So when u open page
in FF on some Linux u get some default font (because browser doesn't
recognize that font). I hope that I've managed to explane a problem
:-) Does anyone has any solution for this problem??? Please it's very
urgent....

Thanks,
Dusan

-- 
made by Dusan

--- End Message ---
--- Begin Message ---
On Tue, 2009-07-28 at 12:07 +0200, Dušan Novaković wrote:

> Hi,
> 
> Is there a possibility that if there is no font installed on client
> side somehow browser finds it and redirect that font form server to
> client machine. For example: I have site that use Microsoft font and
> that font is not available on Linux distributions. So when u open page
> in FF on some Linux u get some default font (because browser doesn't
> recognize that font). I hope that I've managed to explane a problem
> :-) Does anyone has any solution for this problem??? Please it's very
> urgent....
> 
> Thanks,
> Dusan
> 
> -- 
> made by Dusan
> 

Basically that's a big no. At the moment, there is no cross-browser way
to determine if a font is installed on an end system. The best you can
do is to use either a graphic in-place of the text, or use something
like siFr. Both of these methods are only suitable for headings though.

Have you looked at what standard fonts are available to you? The list at
http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html is quite good at
showing these. You can use CSS to give fallback fonts in order of what
you prefer.

There are meant to be plans on how to handle these sorts of situations
in CSS3 though, but you may have to wait a year for the browsers to
adopt!

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

--- End Message ---
--- Begin Message ---
2009/7/28 Dušan Novaković <ndu...@gmail.com>:
> Hi,
>
> Is there a possibility that if there is no font installed on client
> side somehow browser finds it and redirect that font form server to
> client machine. For example: I have site that use Microsoft font and
> that font is not available on Linux distributions. So when u open page
> in FF on some Linux u get some default font (because browser doesn't
> recognize that font). I hope that I've managed to explane a problem
> :-) Does anyone has any solution for this problem??? Please it's very
> urgent....

Not really, no. The choice of font is up to the user's browser.

However, you can, with CSS, set some basic parameters. If, say, you
want to ensure that the users sees a sans-serif font on their browser,
you can use:

font-family: arial, helvetica, verdana, sans-serif

This basically says, ensure that the browser uses arial; if arial
isn't available, use helvetica; if helvetica isn't available, use
verdana; and if verdana isn't available, use whatever sans-serif font
the user has installed on their computer.

Look up the font-family attribute for CSS on the web. There's too much
detail to go into and this is a PHP list, not a CSS list.


-- 
Richard S. Crawford (rscrawf...@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message --- Normally on a newsgroup you will have to give more information if you want people to respond. Most people don't simply want to read your code and figure out what you are finding wrong. You don't even say what the problem is. You are probably getting some kind of response to your code.

Also, look at your logs for Apache or whatever web server you are using, and for Mysql. They may tell you what is wrong.
--- End Message ---
--- Begin Message ---
I need to take this:

   $pastDays = strtotime("-30 days");



$past_day = date("d", $pastDays);

$past_month = date("m", $pastDays);

$past_year =date("y", $pastDays);


And make it into one var to compare to a db field that is formatted like
00/00/00 


--- End Message ---
--- Begin Message ---
On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
> I need to take this:
> 
>    $pastDays = strtotime("-30 days");
> 
> 
> 
> $past_day = date("d", $pastDays);
> 
> $past_month = date("m", $pastDays);
> 
> $past_year =date("y", $pastDays);
> 
> 
> And make it into one var to compare to a db field that is formatted like
> 00/00/00 
> 
> 
Erm, why don't you do this:

$pastDays = strtotime("-30 days");
$date = date("d/m/y", $pastDays);

The date() function allows you to mix in all sorts of characters into
the output it formats, and you can escape characters that have special
meaning with a slash '\' character.

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


--- End Message ---
--- Begin Message ---
Why not this:

$pastDate = date("d/m/y", strtotime("-30 days"));


""Miller, Terion"" <tmil...@springfi.gannett.com> escreveu na mensagem 
news:c6946809.4183%kmille...@springfi.gannett.com...
I need to take this:

   $pastDays = strtotime("-30 days");



$past_day = date("d", $pastDays);

$past_month = date("m", $pastDays);

$past_year =date("y", $pastDays);


And make it into one var to compare to a db field that is formatted like
00/00/00



--- End Message ---
--- Begin Message ---
On Tue, Jul 28, 2009 at 6:32 AM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
> I need to take this:
>
>   $pastDays = strtotime("-30 days");
>
>
>
> $past_day = date("d", $pastDays);
>
> $past_month = date("m", $pastDays);
>
> $past_year =date("y", $pastDays);
>
>
> And make it into one var to compare to a db field that is formatted like
> 00/00/00

Try:

$past_date = date("m/d/y", $pastDays)

Or even:

$past_date = date ("m/d/y", time() - 2592000)

(where 2592000 is 30 * 86400, and 86400 is the number of seconds in one day.)




-- 
Richard S. Crawford (rscrawf...@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

--- End Message ---
--- Begin Message ---


On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

$pastDays = strtotime("-30 days");
$date = date("d/m/y", $pastDays);

Well I tried and got no results from my query and I know there results with 
date ranges in the last 30 days, I basically need to count backward from now() 
30 days I thought strtotime() would work well..but the fields in the db are 
varchar not date fields they are all formatted the same though 00/00/00:

  $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate <= 
$date GROUP BY restaurants.ID ORDER BY 'name' ";

--- End Message ---
--- Begin Message ---
From: Ashley Sheridan
> On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
>> I need to take this:
>> 
>>    $pastDays = strtotime("-30 days");
>> 
>> 
>> 
>> $past_day = date("d", $pastDays);
>> 
>> $past_month = date("m", $pastDays);
>> 
>> $past_year =date("y", $pastDays);
>> 
>> 
>> And make it into one var to compare to a db field that is formatted
like
>> 00/00/00 
>> 
>> 
> Erm, why don't you do this:
> 
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
> 
> The date() function allows you to mix in all sorts of characters into
> the output it formats, and you can escape characters that have special
> meaning with a slash '\' character.

The problem with that is if that field is a string, and not formatted as
YY/MM/DD, then a simple compare won't work in January. You have to break
it down into the three components and compare each one in turn.

Bob McConnell

--- End Message ---
--- Begin Message ---
On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
> 
> 
> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
> 
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
> 
> Well I tried and got no results from my query and I know there results with 
> date ranges in the last 30 days, I basically need to count backward from 
> now() 30 days I thought strtotime() would work well..but the fields in the db 
> are varchar not date fields they are all formatted the same though 00/00/00:
> 
>   $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
> restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate 
> <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
> 

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

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


--- End Message ---
--- Begin Message ---


On 7/28/09 8:41 AM, "Bob McConnell" <r...@cbord.com> wrote:

From: Ashley Sheridan
> On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
>> I need to take this:
>>
>>    $pastDays = strtotime("-30 days");
>>
>>
>>
>> $past_day = date("d", $pastDays);
>>
>> $past_month = date("m", $pastDays);
>>
>> $past_year =date("y", $pastDays);
>>
>>
>> And make it into one var to compare to a db field that is formatted
like
>> 00/00/00
>>
>>
> Erm, why don't you do this:
>
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
>
> The date() function allows you to mix in all sorts of characters into
> the output it formats, and you can escape characters that have special
> meaning with a slash '\' character.

The problem with that is if that field is a string, and not formatted as
YY/MM/DD, then a simple compare won't work in January. You have to break
it down into the three components and compare each one in turn.

Bob McConnell

Hi Bob, they are all formatted in the db as mm/dd/yy

--- End Message ---
--- Begin Message ---
On Tue, 2009-07-28 at 09:41 -0400, Bob McConnell wrote:
> From: Ashley Sheridan
> > On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote:
> >> I need to take this:
> >> 
> >>    $pastDays = strtotime("-30 days");
> >> 
> >> 
> >> 
> >> $past_day = date("d", $pastDays);
> >> 
> >> $past_month = date("m", $pastDays);
> >> 
> >> $past_year =date("y", $pastDays);
> >> 
> >> 
> >> And make it into one var to compare to a db field that is formatted
> like
> >> 00/00/00 
> >> 
> >> 
> > Erm, why don't you do this:
> > 
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> > 
> > The date() function allows you to mix in all sorts of characters into
> > the output it formats, and you can escape characters that have special
> > meaning with a slash '\' character.
> 
> The problem with that is if that field is a string, and not formatted as
> YY/MM/DD, then a simple compare won't work in January. You have to break
> it down into the three components and compare each one in turn.
> 
> Bob McConnell
> 
I assumed that the date field in MySQL was a date or datetime type. It
would be a little silly to store dates in the database any other way?

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


--- End Message ---
--- Begin Message ---


On 7/28/09 8:44 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>
>
> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
>
> Well I tried and got no results from my query and I know there results with 
> date ranges in the last 30 days, I basically need to count backward from 
> now() 30 days I thought strtotime() would work well..but the fields in the db 
> are varchar not date fields they are all formatted the same though 00/00/00:
>
>   $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
> restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate 
> <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
>

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

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



Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol 
thanks guys!

--- End Message ---
--- Begin Message ---
On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:

> 
> 
> On 7/28/09 8:44 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
> 
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
> >
> >
> > On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
> >
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> >
> > Well I tried and got no results from my query and I know there results with 
> > date ranges in the last 30 days, I basically need to count backward from 
> > now() 30 days I thought strtotime() would work well..but the fields in the 
> > db are varchar not date fields they are all formatted the same though 
> > 00/00/00:
> >
> >   $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
> > restaurants, inspections WHERE restaurants.name != '' AND 
> > inspections.inDate <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
> >
> 
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
> 
> Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol 
> thanks guys!
> 

Euro/Brit date formatting? Nah, it's proper data formatting, not what
you crazy Yanks do! ;)


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

--- End Message ---
--- Begin Message ---
On Tue, Jul 28, 2009 at 9:46 AM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
>
>
>
> On 7/28/09 8:44 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>>
>>
>> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>>
>> $pastDays = strtotime("-30 days");
>> $date = date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there results with 
>> date ranges in the last 30 days, I basically need to count backward from 
>> now() 30 days I thought strtotime() would work well..but the fields in the 
>> db are varchar not date fields they are all formatted the same though 
>> 00/00/00:
>>
>>   $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
>> restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate 
>> <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
>>
>
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
> Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol 
> thanks guys!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Also check out Mysql sql date formating / date sub stuff, might make
things easier

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---


On 7/28/09 8:52 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:



On 7/28/09 8:44 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
>
>
> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
>
> Well I tried and got no results from my query and I know there results with 
> date ranges in the last 30 days, I basically need to count backward from 
> now() 30 days I thought strtotime() would work well..but the fields in the db 
> are varchar not date fields they are all formatted the same though 00/00/00:
>
>   $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM 
> restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate 
> <= $date GROUP BY restaurants.ID ORDER BY 'name' ";
>

I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

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



Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol 
thanks guys!

Euro/Brit date formatting? Nah, it's proper data formatting, not what you crazy 
Yanks do! ;)


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

LOL I know we yanks bastardize everything...anyways it still didn't 
work...argh...so the boss thought he'd give me something harder...lovely, now I 
have to figure out how to reverse publish things to quark....get ready guys I 
may be blowing the list up soon with questions (like I don't already)
Terion

--- End Message ---
--- Begin Message ---
> On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:
> > 
> > 
> > On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
> > 
> > $pastDays = strtotime("-30 days");
> > $date = date("d/m/y", $pastDays);
> > 
> > Well I tried and got no results from my query and I know there results with 
> > date ranges in the last 30 days, I basically need to count backward from 
> > now() 30 days I thought strtotime() would work well..but the fields in the 
> > db are varchar not date fields they are all formatted the same though 
> > 00/00/00:
> > 
> >   $sql = "  SELECT DISTINCT restaurants.ID, name, address, inDate 
>>              FROM restaurants, inspections 
>>              WHERE restaurants.name != '' AND inspections.inDate <= $date 
>>              GROUP BY restaurants.ID ORDER BY 'name' ";
> > 
> 
> I believe the query is suspect. From memory, don't you need to enclose
> dates in single quotes in MySQL statements? Also, I believe it uses
> American data format, so you might have to put the month before the day
> like was in Richards example.

Hi,

Instead of using php to work out the 30 days part you could just let the 
database do it:

$sql = "        SELECT DISTINCT restaurants.ID, name, address, inDate 
                FROM restaurants, inspections 
                WHERE restaurants.name != '' AND 

                        CAST(inspections.inDate AS DATE)        <=              
        
                        DATE_SUB(NOW(),INTERVAL 30 DAYS)

                GROUP BY restaurants.ID ORDER BY 'name' ";

You will have to check that the CAST function is working properly on your 
varchar'ed date 
fields before testing this query.  It should point you in the right direction 
though.

Regards

Ian
-- 



--- End Message ---
--- Begin Message ---

On Jul 28, 2009, at 9:55 AM, Miller, Terion wrote:




On 7/28/09 8:52 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-28 at 06:46 -0700, Miller, Terion wrote:



On 7/28/09 8:44 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-28 at 09:42 -0400, Miller, Terion wrote:


On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

$pastDays = strtotime("-30 days");
$date = date("d/m/y", $pastDays);

Well I tried and got no results from my query and I know there results with date ranges in the last 30 days, I basically need to count backward from now() 30 days I thought strtotime() would work well..but the fields in the db are varchar not date fields they are all formatted the same though 00/00/00:

$sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM restaurants, inspections WHERE restaurants.name != '' AND inspections.inDate <= $date GROUP BY restaurants.ID ORDER BY 'name' ";


I believe the query is suspect. From memory, don't you need to enclose
dates in single quotes in MySQL statements? Also, I believe it uses
American data format, so you might have to put the month before the day
like was in Richards example.

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



Ah ha bet that's it didn't notice the euro/brit date formatting there. Lol thanks guys!

Euro/Brit date formatting? Nah, it's proper data formatting, not what you crazy Yanks do! ;)


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

LOL I know we yanks bastardize everything...anyways it still didn't work...argh...so the boss thought he'd give me something harder...lovely, now I have to figure out how to reverse publish things to quark....get ready guys I may be blowing the list up soon with questions (like I don't already)
Terion

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



You can also do this right within MySQL without needing to create a variable. This should work: $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM restaurants, inspections WHERE restaurants.name != '' AND datediff(curdate(),inspections.inDate)>=30 GROUP BY restaurants.ID ORDER BY 'name' ";

Take care,
Floyd


--- End Message ---
--- Begin Message ---
Miller, Terion schrieb:
I need to take this:

   $pastDays = strtotime("-30 days");



$past_day = date("d", $pastDays);

$past_month = date("m", $pastDays);

$past_year =date("y", $pastDays);


And make it into one var to compare to a db field that is formatted like
00/00/00

$result = date("d/m/y", $pastDays);



--- End Message ---
--- Begin Message ---
From: Miller, Terion
On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

> $pastDays = strtotime("-30 days");
> $date = date("d/m/y", $pastDays);
> 
> Well I tried and got no results from my query and I know there
> results with date ranges in the last 30 days, I basically need
> to count backward from now() 30 days I thought strtotime() would
> work well..but the fields in the db are varchar not date fields
> they are all formatted the same though 00/00/00:

If the dates are really stored as varchar, you are doing a lexical
comparison on a field that is meaningless in that context. You will need
to break the string down somewhere and do three separate comparisons.

Bob McConnell

--- End Message ---
--- Begin Message ---


<,snip>
>

You can also do this right within MySQL without needing to create a
variable.  This should work:
$sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
restaurants, inspections WHERE restaurants.name != '' AND
datediff(curdate(),inspections.inDate)>=30 GROUP BY restaurants.ID
ORDER BY 'name' ";

Take care,
Floyd



Ok I have to do the same thing again but with even more variables posted from a 
form
I have a form where a user can choose a date range currently the form returns 6 
variables (bmonth, bday, byear, emonth, eday, eyear) now I have to take those 
and get them all formatted together (well the bmonth, bday, byear together) in 
the mm/dd/yy format

Wait can't I.....
$month = $date(m, $bmonth) like that but then I still end up with 3

$month, $day, $year.... Does that work like that $date(m/d/y, $month, $day, 
$year)

--- End Message ---
--- Begin Message ---
On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell<r...@cbord.com> wrote:
> From: Miller, Terion
> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
>> $pastDays = strtotime("-30 days");
>> $date = date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there
>> results with date ranges in the last 30 days, I basically need
>> to count backward from now() 30 days I thought strtotime() would
>> work well..but the fields in the db are varchar not date fields
>> they are all formatted the same though 00/00/00:
>
> If the dates are really stored as varchar, you are doing a lexical
> comparison on a field that is meaningless in that context. You will need
> to break the string down somewhere and do three separate comparisons.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Teri,

have you considered making the field a date/ datetime type? You could
add the column, then copy the data over with a sql statement casting
it to the correct date format you require and then drop the original
column

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---


On 7/28/09 9:40 AM, "Bastien Koert" <phps...@gmail.com> wrote:

On Tue, Jul 28, 2009 at 10:34 AM, Bob McConnell<r...@cbord.com> wrote:
> From: Miller, Terion
> On 7/28/09 8:35 AM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
>
>> $pastDays = strtotime("-30 days");
>> $date = date("d/m/y", $pastDays);
>>
>> Well I tried and got no results from my query and I know there
>> results with date ranges in the last 30 days, I basically need
>> to count backward from now() 30 days I thought strtotime() would
>> work well..but the fields in the db are varchar not date fields
>> they are all formatted the same though 00/00/00:
>
> If the dates are really stored as varchar, you are doing a lexical
> comparison on a field that is meaningless in that context. You will need
> to break the string down somewhere and do three separate comparisons.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Teri,

have you considered making the field a date/ datetime type? You could
add the column, then copy the data over with a sql statement casting
it to the correct date format you require and then drop the original
column

--

Bastien

Cat, the other other white meat

I don't think I can this data is being pulled from our county health site, so 
it comes in how they put it on their page (scraping here)  and I'm grabbing it 
using regex. (and this is totally public info so it's legit-my employer tells 
me)



--- End Message ---
--- Begin Message ---
On Tue, Jul 28, 2009 at 10:40 AM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
>
>
>
> <,snip>
>>
>
> You can also do this right within MySQL without needing to create a
> variable.  This should work:
> $sql = "SELECT DISTINCT restaurants.ID, name, address, inDate FROM
> restaurants, inspections WHERE restaurants.name != '' AND
> datediff(curdate(),inspections.inDate)>=30 GROUP BY restaurants.ID
> ORDER BY 'name' ";
>
> Take care,
> Floyd
>
>
>
> Ok I have to do the same thing again but with even more variables posted from 
> a form
> I have a form where a user can choose a date range currently the form returns 
> 6 variables (bmonth, bday, byear, emonth, eday, eyear) now I have to take 
> those and get them all formatted together (well the bmonth, bday, byear 
> together) in the mm/dd/yy format
>
> Wait can't I.....
> $month = $date(m, $bmonth) like that but then I still end up with 3
>
> $month, $day, $year.... Does that work like that $date(m/d/y, $month, $day, 
> $year)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Use strtotime to convert a text string into a time value that php can
then use to figure out a date.

$date = date('m/d/y', strtotime("$month/$day/$year");

-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message --- This may be more of a MySQL question than PHP, but I'm hoping someone can point me in the right direction. I have working code (below) that pulls data from a particular category in our db. I'd like to be able to pull data from multiple categories in the same db and place them on the same page.

I've been working on this for the last 4 days with no luck. Some pages say that you can't do multiple MySQL queries while others say there is a workaround but I haven't found it. Does anyone know how to do this?

Thanks,
Frank

--------

<?php require_once("/home/balcone/db_login.php"); ?> // in header

<?php
        $item_list = "";
        $cat1 = "01100-01200-01300-06403";
$result = mysql_query("SELECT itemid,description,unitprice FROM catalog WHERE categories='" . $cat1 . "' ORDER BY itemid",$db);

while ($item = mysql_fetch_assoc($result))
{
$item_list .= "<tr><td>" . $item['itemid'] . "</td>
<td><a href=\".../shop.cgi?c=detail.htm&amp;itemid=" . $item['itemid'] . "=1\">". $item['description'] ."</a></td>
        <td align=\"right\">$". money_format('%i', $item['unitprice']) ."</td>
        <td></tr>";
}
echo "<table border=\"1\"><tr><th>Item ID</th><th>Description<br / ><font size=\"-1\">(Click for more info)</font></th><th>Price Each</ th><th>Purchase</th></tr>$item_list</table>";
?>

--- End Message ---
--- Begin Message ---
On Tue, Jul 28, 2009 at 10:11 AM, <sono...@fannullone.us> wrote:
>        This may be more of a MySQL question than PHP, but I'm hoping someone
> can point me in the right direction.  I have working code (below) that pulls
> data from a particular category in our db.  I'd like to be able to pull data
> from multiple categories in the same db and place them on the same page.
>
>        I've been working on this for the last 4 days with no luck.  Some
> pages say that you can't do multiple MySQL queries while others say there is
> a workaround but I haven't found it.  Does anyone know how to do this?
>
> Thanks,
> Frank
>
> --------
>
> <?php require_once("/home/balcone/db_login.php"); ?> // in header
>
> <?php
>        $item_list = "";
>        $cat1 = "01100-01200-01300-06403";
>        $result = mysql_query("SELECT itemid,description,unitprice FROM
> catalog WHERE categories='" . $cat1 . "'  ORDER BY itemid",$db);
>
> while ($item = mysql_fetch_assoc($result))
> {
> $item_list .= "<tr><td>" . $item['itemid'] . "</td>
>        <td><a href=\".../shop.cgi?c=detail.htm&amp;itemid=" .
> $item['itemid'] . "=1\">". $item['description'] ."</a></td>
>        <td align=\"right\">$". money_format('%i', $item['unitprice'])
> ."</td>
>        <td></tr>";
> }
> echo "<table border=\"1\"><tr><th>Item ID</th><th>Description<br /><font
> size=\"-1\">(Click for more info)</font></th><th>Price
> Each</th><th>Purchase</th></tr>$item_list</table>";
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

change it to an IN clause for the categories

$result = mysql_query("SELECT itemid,description,unitprice FROM
catalog WHERE categories in('$cat1',"$cat2',$cat3','$catN')  ORDER BY
itemid",$db);


-- 

Bastien

Cat, the other other white meat

--- End Message ---

Reply via email to