OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
php-general Digest 20 Mar 2008 01:08:50 -0000 Issue 5357

php-general-digest-helplists.php.net
Date: Wed Mar 19 2008 - 20:08:50 CDT


php-general Digest 20 Mar 2008 01:08:50 -0000 Issue 5357

Topics (messages 271777 through 271866):

Re: Is this the best way?
        271777 by: Jason Pruim
        271781 by: Stut
        271784 by: TG

Re: Fastest way to get table records' number
        271778 by: Daniel Brown
        271780 by: Andrew Ballard
        271783 by: Stut
        271785 by: Nathan Nobbe
        271788 by: Mikey
        271790 by: tedd
        271791 by: Andrew Ballard
        271792 by: Stut
        271793 by: Andrew Ballard
        271796 by: jeffry s
        271797 by: Stut
        271799 by: Edward Kay
        271831 by: TG
        271834 by: Andrew Ballard
        271836 by: Daniel Brown
        271839 by: It Maq
        271840 by: David Giragosian
        271841 by: Daniel Brown
        271842 by: TG

Re: Closures
        271779 by: Zoltán Németh

Re: question about php with sql database
        271782 by: Daniel Brown

Re: Objects as array key names??
        271786 by: Jim Lucas
        271852 by: Nathan Nobbe

Re: Detecting \u0000 in a string...
        271787 by: Mikey

php book
        271789 by: alexus
        271794 by: Daniel Brown
        271795 by: tedd
        271801 by: George Pitcher
        271813 by: Daniel Brown

Double click problem
        271798 by: tedd
        271800 by: Dan Joseph
        271802 by: Stut
        271803 by: Edward Kay
        271804 by: Edward Kay
        271805 by: Eric Butera
        271807 by: Daniel Brown
        271808 by: Daniel Brown
        271812 by: tedd
        271816 by: Richard Heyes
        271824 by: tedd
        271826 by: Jim Lucas
        271827 by: Daniel Brown

algorithm of pages beaking
        271806 by: It Maq
        271809 by: Daniel Brown
        271810 by: tedd
        271814 by: Edward Kay
        271858 by: George J
        271864 by: jeffry s

selling gpl software?
        271811 by: jeffry s
        271815 by: Stut
        271817 by: Richard Heyes
        271819 by: Daniel Brown
        271820 by: bruce
        271821 by: tedd
        271823 by: Richard Heyes
        271828 by: Colin Guthrie
        271830 by: Daniel Brown
        271832 by: bruce
        271833 by: jeffry s
        271835 by: Daniel Brown
        271838 by: jeffry s

Re: What's wrong the __autoload()?
        271818 by: Greg Donald

Checking how many letters are in a string.
        271822 by: Dotan Cohen
        271825 by: Richard Heyes
        271829 by: tedd
        271837 by: TG
        271844 by: Dotan Cohen
        271857 by: tedd

eval uquestion
        271843 by: chetan rane
        271845 by: Andrew Ballard

Newbie question, Which way is best?
        271846 by: George J
        271847 by: Daniel Brown
        271848 by: Andrew Ballard
        271849 by: George J
        271850 by: Daniel Brown
        271851 by: Jason Pruim
        271853 by: George J

Re: Newbie question, Which way is best?]
        271854 by: Shawn McKenzie
        271856 by: George J

Re: SOAP Server in PHP4
        271855 by: Eric Gorr

fwrite/fclose troubles
        271859 by: Mark Weaver
        271860 by: Stut
        271866 by: Stut

MySQL Group?
        271861 by: John Taylor-Johnston
        271863 by: John Taylor-Johnston
        271865 by: George J

Re: Newbie ' If Statement' Question
        271862 by: Dan

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Just to warn you... I've been up for about 30 minutes and I'm still on
my first shot of caffeine... Sorry if things don't make 100% sense :)

On Mar 18, 2008, at 10:27 PM, Jochem Maas wrote:

> Jason Pruim schreef:
>> On Mar 18, 2008, at 3:20 PM, Jochem Maas wrote:
>>> what started out as a simple little reply bloated out into an
>>> inpromptu brain
>>> fart ... lots of bla .. enjoy :-)
>>>
>>> Jason Pruim schreef:
>>>> Hi everyone,
>>>> I am attempting to add a little error checking for a very simple
>>>> login system. The info is stored in a MySQL database, and I am
>>>> using mysqli to connect to it. I have it working with the
>>>> solution provided below, but I am wondering if this is the right
>>>> way to do it or if there is a better way?
>>>
>>> at an abstract level you might consider that your function could
>>> simply
>>> always return a boolean (true = logged in, false = not logged in)
>>> and that the
>>> rest of the application retrieves all the other data via the session
>>> (as opposed to returning half the data and storing half in the
>>> session)
>> I think this is what I am attempting to do... Just going about it
>> all wrong...
>
> start from scratch again?

By the time I'm ready to release this, I'll have 50 versions :)
>
>
>> I want the pages to check to see if the person is still logged in
>> and if they are, then it's pulling live data from the database...
>> So maybe I should edit my authentication function...
>
> maybe.
> there are two different things being confused:
>
> 1. checking logged in state.
> 2. attempting to login.

Would it make sense to set up a function to see if they are
authenticated, and if they aren't, have it call the authentication
function?
>
>
> function getUserData()
> {
> if (isAuthenticatedUser())
> return $_SESSION['user']['data'];
>
> return null;
> }
>
> function isAuthenticatedUser()
> {
> return (isset($_SESSION['user']['authenticated']) &&
> $_SESSION['user']['authenticated']);
> }
>
> function authenticateUser($u, $p, $cc = false)
> {
> if (($iau = isAuthenticatedUser()) && !$cc)
> throw Exception('Already logged in!');
>
> $cmd = $iau ? 'verify account' : 'login';

I've seen these kinds of things in other scripts that I've looked at,
but don't totally understand what the : does between 2 options...
>
>
> if (!($p = trim($p)) || !($u = trim($u)))
> throw Exception('Cannot '.$cmd.' without credentials!');
>
>
> $p = mysql_real_escape_string($p);
> $u = mysql_real_escape_string($u);
>
> if (!($res = mysql_query("SELECT * FROM `users` WHERE 'pwd'='$p'
> AND `usr`='$u'")))
> throw Exception('Cannot '.$cmd.', verification system error.');
>
> if (mysql_num_rows($res) != 1)
> return false;
>
> if (!($row = mysql_fetch_assoc($res)))
> throw Exception('Cannot '.$cmd.', verification system error.');
>
> if ($iau)
> return (int)$_SESSION['user']['data']['id'] === (int)$row['id'];
>
> unset($row['pwd']);
>
> $_SESSION['user'] = array(
> 'authenticated' => true,
> 'data' => $row,
> );
>
> return true;
> }
>
>> function auth($loggedin) {
>> query database to see if username & Password match;
>> write certain variables into session (Or maybe into the cache?)

I'm going to try this suggestion in just a few minutes... Thanks for
your help. I had it all written and working without using functions,
but then I wanted to extend and all hell broke loose :)

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruimraoset.com

attached mail follows:


Jason Pruim wrote:
>> $cmd = $iau ? 'verify account' : 'login';
>
> I've seen these kinds of things in other scripts that I've looked at,
> but don't totally understand what the : does between 2 options...

$cmd = $iau ? 'verify account' : 'login';
    if (^^^^) { $cmd = ^^^^^^^^^^^^^^^^; } else { $cmd = ^^^^^^^; }

Simple as that.

-Stut

--
http://stut.net/

attached mail follows:


> Just to warn you... I've been up for about 30 minutes and I'm still on
> my first shot of caffeine... Sorry if things don't make 100% sense :)

Same here.

> > start from scratch again?
>
> By the time I'm ready to release this, I'll have 50 versions :)

Measure twice, cut once. Not that I don't go through many versions when
creating things, but it's nice to do as much design and theory before the
coding so you don't have to end up with 50 versions. But that's all part
of learning, so it's all good.

> Would it make sense to set up a function to see if they are
> authenticated, and if they aren't, have it call the authentication
> function?

If that's how you want it designed. Yes. A typical setup would be
something like this:

if (!$authenticated) {
   // show login form or redirect to login page or show error
   exit(); // I like die() better myself, but it's your personal preference
}

// all the rest of your code here

> I've seen these kinds of things in other scripts that I've looked at,
> but don't totally understand what the : does between 2 options...

That's a "ternary operation". It's used as shorthand for a simple
if...then.. else...

$val = ($condition) ? "condition is true" : "condition is false";

is the same as...

if ($condition) {
  $val = "condition is true";
} else {
  $val = "condition is false";
}

It just takes whatever the value before the ":" and assigns it to the
variable if true, takes the value after the ":" and assigns it if false.

The values can be from functions or anything that returns a value, it doesn't
have to be a straight variable type value.

-TG

attached mail follows:


On Tue, Mar 18, 2008 at 11:43 PM, Shelley <myphplistgmail.com> wrote:
> Hi all,
>
> What do you think is the FASTEST sql to get the total number of a table
> with millions of records?

    That question would be better on the PHP-DB list, so for archive's
sake, I'm CC'ing that list.

    $sql = "SELECT COUNT(*) FROM your_table";

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


On Tue, Mar 18, 2008 at 11:47 PM, Nathan Nobbe <quickshiftingmail.com>
wrote:

> On Tue, Mar 18, 2008 at 11:43 PM, Shelley <myphplistgmail.com> wrote:
>
> > Hi all,
> >
> > What do you think is the FASTEST sql to get the total number of a table
> > with millions of records?
>
>
> when you say 'total number' do you mean the total number of records? in
> that case assuming the table has a field 'id' then i think
> select count(id) from some_table;
>
> -nathan

That works; I'm just wondering why you went with a count on an 'ID' column
rather than COUNT(*).

Andrew

attached mail follows:


Shelley wrote:
> What do you think is the FASTEST sql to get the total number of a table
> with millions of records?

Generally speaking 'select count(1) from table' is the quickest way, but
it really depends on the database and storage engine you're using. Your
best bet is to look at the documentation for the database you're using
or find a mailing list for it.

-Stut

--
http://stut.net/

attached mail follows:


On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com> wrote:

> That works; I'm just wondering why you went with a count on an 'ID' column
> rather than COUNT(*).

ouch, it looks like im horribly wrong :O
mysql> select count(*) from table;
+----------+
| count(*) |
+----------+
| 361724 |
+----------+
1 row in set (0.90 sec)

mysql> select count(id) from table;
+------------+
| count(did) |
+------------+
| 361724 |
+------------+
1 row in set (4.56 sec)

-nathan

attached mail follows:


Nathan Nobbe wrote:
> On Tue, Mar 18, 2008 at 11:43 PM, Shelley <myphplistgmail.com> wrote:
>
>> Hi all,
>>
>> What do you think is the FASTEST sql to get the total number of a table
>> with millions of records?
>
>
> when you say 'total number' do you mean the total number of records? in
> that case assuming the table has a field 'id' then i think
> select count(id) from some_table;
>
> -nathan
>

If you are talking about millions of rows then the fastest way is to put
a trigger on create and delete on the table in question that updates a
single column in another table that is a counter.

HTH,

Mikey

attached mail follows:


At 10:35 AM -0400 3/19/08, Nathan Nobbe wrote:
>On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com> wrote:
>
>> That works; I'm just wondering why you went with a count on an 'ID' column
>> rather than COUNT(*).
>
>
>ouch, it looks like im horribly wrong :O
>mysql> select count(*) from table;
>+----------+
>| count(*) |
>+----------+
>| 361724 |
>+----------+
>1 row in set (0.90 sec)
>
>mysql> select count(id) from table;
>+------------+
>| count(did) |
>+------------+
>| 361724 |
>+------------+
>1 row in set (4.56 sec)
>
>-nathan

That surprised me as well.

I thought that (*) meant "look up everything" and would have figured
that (id) would have been quicker.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


On Wed, Mar 19, 2008 at 10:35 AM, Nathan Nobbe <quickshiftingmail.com>
wrote:

> On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com>
> wrote:
>
> > That works; I'm just wondering why you went with a count on an 'ID'
> > column
> > rather than COUNT(*).
>
>
> ouch, it looks like im horribly wrong :O
> mysql> select count(*) from table;
> +----------+
> | count(*) |
> +----------+
> | 361724 |
> +----------+
> 1 row in set (0.90 sec)
>
> mysql> select count(id) from table;
> +------------+
> | count(did) |
> +------------+
> | 361724 |
> +------------+
> 1 row in set (4.56 sec)
>
> -nathan
>

I'm not sure, but I think that's because COUNT(*) simply counts the number
of rows (which the query engine may be able to look up some other way than
looping through all the rows) whereas COUNT(did) has to read each row to
determine if there is a NULL value. I'm not sure if the engine can
short-circuit this if it knows that the columns cannot be NULL, but then we
are really headed to a database board rather than the PHP general list now.

Andrew

attached mail follows:


On 19 Mar 2008, at 14:53, tedd wrote:
> At 10:35 AM -0400 3/19/08, Nathan Nobbe wrote:
>> On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard
>> <aballardgmail.com> wrote:
>>
>>> That works; I'm just wondering why you went with a count on an
>>> 'ID' column
>>> rather than COUNT(*).
>>
>>
>> ouch, it looks like im horribly wrong :O
>> mysql> select count(*) from table;
>> +----------+
>> | count(*) |
>> +----------+
>> | 361724 |
>> +----------+
>> 1 row in set (0.90 sec)
>>
>> mysql> select count(id) from table;
>> +------------+
>> | count(did) |
>> +------------+
>> | 361724 |
>> +------------+
>> 1 row in set (4.56 sec)
>>
>> -nathan
>
> That surprised me as well.
>
> I thought that (*) meant "look up everything" and would have figured
> that (id) would have been quicker.

Using count(*) can be optimised, as can count(1) which is what I
usually use. Using a specific field is harder to optimise.

-Stut

--
http://stut.net/

attached mail follows:


On Wed, Mar 19, 2008 at 10:53 AM, tedd <tedd.sperlinggmail.com> wrote:

>
>
>
> At 10:35 AM -0400 3/19/08, Nathan Nobbe wrote:
> >On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com> wrote:
> >
> >> That works; I'm just wondering why you went with a count on an 'ID' column
> >> rather than COUNT(*).
> >
> >
> >ouch, it looks like im horribly wrong :O
> >mysql> select count(*) from table;
> >+----------+
> >| count(*) |
> >+----------+
> >| 361724 |
> >+----------+
> >1 row in set (0.90 sec)
> >
> >mysql> select count(id) from table;
> >+------------+
> >| count(did) |
> >+------------+
> >| 361724 |
> >+------------+
> >1 row in set (4.56 sec)
> >
> >-nathan
>
> That surprised me as well.
>
> I thought that (*) meant "look up everything" and would have figured
> that (id) would have been quicker.
>
>

You generally want to explicitly specify column names rather than
using SELECT *, because it returns everything even if you don't need
it. But for aggregate COUNT, I'm not surprised by the results Nathan
got.

Andrew

attached mail follows:


On Wed, Mar 19, 2008 at 10:57 PM, Andrew Ballard <aballardgmail.com> wrote:

> On Wed, Mar 19, 2008 at 10:53 AM, tedd <tedd.sperlinggmail.com> wrote:
>
> >
> >
> >
> > At 10:35 AM -0400 3/19/08, Nathan Nobbe wrote:
> > >On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com>
> wrote:
> > >
> > >> That works; I'm just wondering why you went with a count on an 'ID'
> column
> > >> rather than COUNT(*).
> > >
> > >
> > >ouch, it looks like im horribly wrong :O
> > >mysql> select count(*) from table;
> > >+----------+
> > >| count(*) |
> > >+----------+
> > >| 361724 |
> > >+----------+
> > >1 row in set (0.90 sec)
> > >
> > >mysql> select count(id) from table;
> > >+------------+
> > >| count(did) |
> > >+------------+
> > >| 361724 |
> > >+------------+
> > >1 row in set (4.56 sec)
> > >
> > >-nathan
> >
> > That surprised me as well.
> >
> > I thought that (*) meant "look up everything" and would have figured
> > that (id) would have been quicker.
> >
> >
>
> You generally want to explicitly specify column names rather than
> using SELECT *, because it returns everything even if you don't need
> it. But for aggregate COUNT, I'm not surprised by the results Nathan
> got.
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
what about SELECT MAX(id) FROM table :)

attached mail follows:


jeffry s wrote:
> what about SELECT MAX(id) FROM table :)

Won't give you the number of records, just the highest ID.

-Stut

--
http://stut.net/

attached mail follows:


> > > At 10:35 AM -0400 3/19/08, Nathan Nobbe wrote:
> > > >On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com>
> > wrote:
> > > >
> > > >> That works; I'm just wondering why you went with a count
> on an 'ID'
> > column
> > > >> rather than COUNT(*).
> > > >
> > > >
> > > >ouch, it looks like im horribly wrong :O
> > > >mysql> select count(*) from table;
> > > >+----------+
> > > >| count(*) |
> > > >+----------+
> > > >| 361724 |
> > > >+----------+
> > > >1 row in set (0.90 sec)
> > > >
> > > >mysql> select count(id) from table;
> > > >+------------+
> > > >| count(did) |
> > > >+------------+
> > > >| 361724 |
> > > >+------------+
> > > >1 row in set (4.56 sec)
> > > >
> > > >-nathan
> > >
> > > That surprised me as well.
> > >
> > > I thought that (*) meant "look up everything" and would have figured
> > > that (id) would have been quicker.
> > >
> > >
> >
> > You generally want to explicitly specify column names rather than
> > using SELECT *, because it returns everything even if you don't need
> > it. But for aggregate COUNT, I'm not surprised by the results Nathan
> > got.
> >

> what about SELECT MAX(id) FROM table :)

But that's not the same thing. If any rows have been deleted, then this
would give the wrong answer.

Edward

attached mail follows:


It seems that count(*) pulls all the data from the row then performs a count
increment whereas count(did) only pulls the 'did' column.

I wonder if count(did) is the same speed as count(1) or if it will depend on
how much/what type of data is in 'did'.

I also wonder why count() takes a parameter. Isn't it always going to count
+1 for the row? I'll have to look that up sometime.

-TG

----- Original Message -----
From: "Nathan Nobbe" <quickshiftingmail.com>
To: "Andrew Ballard" <aballardgmail.com>
Cc: "PHP General list" <php-generallists.php.net>
Date: Wed, 19 Mar 2008 10:35:16 -0400
Subject: Re: [PHP] Fastest way to get table records' number

> On Wed, Mar 19, 2008 at 9:42 AM, Andrew Ballard <aballardgmail.com> wrote:
>
> > That works; I'm just wondering why you went with a count on an 'ID' column
> > rather than COUNT(*).
>
>
> ouch, it looks like im horribly wrong :O
> mysql> select count(*) from table;
> +----------+
> | count(*) |
> +----------+
> | 361724 |
> +----------+
> 1 row in set (0.90 sec)
>
> mysql> select count(id) from table;
> +------------+
> | count(did) |
> +------------+
> | 361724 |
> +------------+
> 1 row in set (4.56 sec)
>
> -nathan
>
>

attached mail follows:


On Wed, Mar 19, 2008 at 1:04 PM, TG <tg-phpgryffyndevelopment.com> wrote:
>
> It seems that count(*) pulls all the data from the row then performs a count
> increment whereas count(did) only pulls the 'did' column.

Again, I don't believe COUNT(*) pulls any data. If there is a row, it
simply counts it. The row could be full of NULLS (if allowed by your
schema - yikes) and it will still be counted. I'd guess that COUNT(1)
does the same thing. COUNT(did) does only examine the `did` column,
but NULL values are excluded from the count.

> I wonder if count(did) is the same speed as count(1) or if it will depend on
> how much/what type of data is in 'did'.
>
>
> I also wonder why count() takes a parameter. Isn't it always going to count
> +1 for the row? I'll have to look that up sometime.

It takes a parameter because it depends on what you want to count.
COUNT(*) will return the number of rows matching the WHERE clause.
COUNT(`column_name`) will return the number of non-NULL values in the
column `column_name`. You could have a million rows in the table, but
if every row has NULL in `column_name`, the COUNT() will return 0.
There is also COUNT(DISTINCT `column_name`), which counts the number
of distinct, non-NULL values in the column.

Andrew

attached mail follows:


On Wed, Mar 19, 2008 at 1:19 PM, Andrew Ballard <aballardgmail.com> wrote:
> On Wed, Mar 19, 2008 at 1:04 PM, TG <tg-phpgryffyndevelopment.com> wrote:
> >
> > It seems that count(*) pulls all the data from the row then performs a count
> > increment whereas count(did) only pulls the 'did' column.
>
> Again, I don't believe COUNT(*) pulls any data. If there is a row, it
> simply counts it. The row could be full of NULLS (if allowed by your
> schema - yikes) and it will still be counted. I'd guess that COUNT(1)
> does the same thing. COUNT(did) does only examine the `did` column,
> but NULL values are excluded from the count.

    You are correct, sir! COUNT(*) doesn't look into the data at all,
it just counts all rows. Keep in mind that COUNT(*) may very well
return a different result than the cardinality of the table, since
COUNT(*) couldn't care less if the row is unique or not.

> > I wonder if count(did) is the same speed as count(1) or if it will depend on
> > how much/what type of data is in 'did'.
> >
> >
> > I also wonder why count() takes a parameter. Isn't it always going to count
> > +1 for the row? I'll have to look that up sometime.
>
> It takes a parameter because it depends on what you want to count.
> COUNT(*) will return the number of rows matching the WHERE clause.
> COUNT(`column_name`) will return the number of non-NULL values in the
> column `column_name`. You could have a million rows in the table, but
> if every row has NULL in `column_name`, the COUNT() will return 0.
> There is also COUNT(DISTINCT `column_name`), which counts the number
> of distinct, non-NULL values in the column.

    You can extend a SELECT COUNT(*) query almost exactly like you
would a basic SELECT query. Examples:

    SELECT COUNT(*) FROM users WHERE username LIKE '%dan%';
    SELECT COUNT(DISTINCT color) FROM products;
    SELECT COUNT(*) FROM table LIMIT 0,1;

    Any limits or the like on the query (such as in the last example)
will pretty much be ignored, though, because COUNT(*) only returns the
number of matching rows, not any other data whatsoever.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


Hi,

did you try mysql_num_rows ?

--- Andrew Ballard <aballardgmail.com> wrote:

> On Wed, Mar 19, 2008 at 1:04 PM, TG
> <tg-phpgryffyndevelopment.com> wrote:
> >
> > It seems that count(*) pulls all the data from
> the row then performs a count
> > increment whereas count(did) only pulls the 'did'
> column.
>
> Again, I don't believe COUNT(*) pulls any data. If
> there is a row, it
> simply counts it. The row could be full of NULLS (if
> allowed by your
> schema - yikes) and it will still be counted. I'd
> guess that COUNT(1)
> does the same thing. COUNT(did) does only examine
> the `did` column,
> but NULL values are excluded from the count.
>
> > I wonder if count(did) is the same speed as
> count(1) or if it will depend on
> > how much/what type of data is in 'did'.
> >
> >
> > I also wonder why count() takes a parameter.
> Isn't it always going to count
> > +1 for the row? I'll have to look that up
> sometime.
>
> It takes a parameter because it depends on what you
> want to count.
> COUNT(*) will return the number of rows matching the
> WHERE clause.
> COUNT(`column_name`) will return the number of
> non-NULL values in the
> column `column_name`. You could have a million rows
> in the table, but
> if every row has NULL in `column_name`, the COUNT()
> will return 0.
> There is also COUNT(DISTINCT `column_name`), which
> counts the number
> of distinct, non-NULL values in the column.
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

      ____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

attached mail follows:


Doesn't the 1 in "Select count(1) from table" refer to the first
column in the table, like order by 1 asc?

David

attached mail follows:


On Wed, Mar 19, 2008 at 1:53 PM, David Giragosian <dgiragosiangmail.com> wrote:
> Doesn't the 1 in "Select count(1) from table" refer to the first
> column in the table, like order by 1 asc?

    No, it evaluates to Boolean TRUE. It's the same as the one (1) here:

    SELECT * FROM table WHERE 1;

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


First, I swore I deleted that message before I sent it. Rethought the whole
count(*) thing and re-read the OP that said count(*) was faster. Oh well..
hah..

Second.. about mysql_num_rows()... at that point, the database has
collected the data and sent it to the PHP script. If you're pulling the
data anyway, that's cool, but if all you want is a count then you're better
off letting the database do the heavy lifting and only returning a single
column, single row with the count.

Say for instance, you have a table with 1000 rows:

SELECT * FROM sometable

This will grab all the data, send it all to PHP.

SELECT count(*) FROM sometable

Sends a single row to PHP. Leaving the heavy lifting to the DB server. This
is a good thing if you don't need any of the data, just a count.

-TG

----- Original Message -----
From: It Maq <itmaqurfeyahoo.com>
To: PHP General list <php-generallists.php.net>
Date: Wed, 19 Mar 2008 10:38:16 -0700 (PDT)
Subject: Re: [PHP] Fastest way to get table records' number

> Hi,
>
> did you try mysql_num_rows ?
>
> --- Andrew Ballard <aballardgmail.com> wrote:
>
> > On Wed, Mar 19, 2008 at 1:04 PM, TG
> > <tg-phpgryffyndevelopment.com> wrote:
> > >
> > > It seems that count(*) pulls all the data from
> > the row then performs a count
> > > increment whereas count(did) only pulls the 'did'
> > column.
> >
> > Again, I don't believe COUNT(*) pulls any data. If
> > there is a row, it
> > simply counts it. The row could be full of NULLS (if
> > allowed by your
> > schema - yikes) and it will still be counted. I'd
> > guess that COUNT(1)
> > does the same thing. COUNT(did) does only examine
> > the `did` column,
> > but NULL values are excluded from the count.

attached mail follows:


> in short, functional programming support would have been great in php if it
> had been incorporated early on, at this point i can live without it. if we
> were going to see support for anything anonymous that i would welcome it
> would be anonymous objects and the ability to create an object on the fly
> from an interface as per java 5. o and inner classes would be nice too, but
> maybe traits would address that desire, i dont know.
>
> -nathan

I agree with this

greets,
Zoltán Németh

attached mail follows:


    Again, another question better-asked on the PHP-DB list, so it's
being CC'd there. Responses in-line....

On Wed, Mar 19, 2008 at 1:08 AM, Sudhakar <sudhakararaoggmail.com> wrote:
> instead of using mysql database which is conventionally used as database
> with php, if sql server database is used with php are there any major
> differences to keep in mind.

    There are going to be some SQL syntax differences, yes. Despite
the name Standard Query Language, it's not really standard by anything
but the most basic of queries.

> 1.
> are the connection statements ex = $conn = mysql_connect($hostname, $user,
> $dbpassword); etc does these remain the same or are they different.

    No, that's for MySQL, hence the name of the function,
mysql_connect(). You'll want to use mssql_connect() and the
mssql_****() family of functions. RTFM: http://php.net/mssql

    If you're on a *NIX-like box, you'll also need to build and install FreeTDS.

> 2.
> unlike in mysql with phpmyadmin which is browser based to access databases
> and tables how to access sql server for the same functionality

    STFW before asking here:
http://www.google.com/search?q=phpmyadmin+sql+server

> 3.
> can anyone provide a link about a manual for using sql database with php

    Again, STFW and RTFM.
    http://www.google.com/search?q=php+sql+server
    http://php.net/mysql
    http://php.net/mssql

    Also, keep in mind that you'll have to rewrite all parts of your
code that currently utilize MySQL to convert it to MSSQL/SQL Server.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


Nathan Nobbe wrote:
> another developer brought to my attention the spl method spl_object_hash()
> method which afforded a mod in the previously posted class whereby foreach
> could be used properly. also, it allows a more efficient internal
> implementation. however, to my dismay, it appears that implementing
> ArrayAccess does not (not just in this scenario, but in any) allow the class
> which does so to hook into the global array methods such as array_keys() or
> array_key_exists(). in this sense, i see it as being only about halfway as
> useful as it could (or should) be.
> what i see ArrayAccess in php as, is something quite similar to properties
> in vb.net, if anyones familiar w/ that.
> http://www.vbdotnetheaven.com/Uploadfile/rajeshvs/PropertiesInVbDotNet04192005060237AM/PropertiesInVbDotNet.aspx
>
> this is the second scenario where i think there could be c code in php
> itself that would override standard behavior provided an spl definition in
> user space. sure, the internal code would run a bit slower but imagine
> wrapping it in #ifdef directives and mapping those to a configure flag
> whereby if spl wasnt enabled that code wasnt included. i think that would
> be adequate and it would allow spl to be even more powerful, giving php
> programmers the ability to more dramatically, semantically modify the core
> w/o writing a scrap of low-level code.
>
> if anybody cares, im happy to send the code for the revision of ObjectArray
> that allows usage of the foreach construct over instances of it.
>
> -nathan
>

I would be interested in your examples. From what you described, I can't see in
my head how it all goes together.

Thanks

--
Jim Lucas

    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
     by William Shakespeare

attached mail follows:


On Wed, Mar 19, 2008 at 10:37 AM, Jim Lucas <listscmsws.com> wrote:

> I would be interested in your examples. From what you described, I can't
> see in
> my head how it all goes together.
>

there was one caveat; i had to introduce a keyVal() instance method so
client code can get the object that is the current array 'key' because
internally it is the hash from spl_object_hash(), which is a string. using
this hash cut down on a number of loops that were in the old implementation
so i suspect this one is a little faster to boot.

<?php
class ObjectArray implements ArrayAccess, Countable, Iterator{
    private $offsets = array(); // for optimizing iterator
implementation
    private $indexes = array(); // array of object hashes
    private $values = array(); // array of mixed values
    private $curOffset = '';
    private $curOffsetNum = -1;
    private $totalElements = 0;

/// Countable interface
    public function count() {
        return $this->totalElements;
    }

    /**
     * a function to grab the actual value of the key,
     * if needed
     */
    public function keyVal($key=null) {
        if(!is_null($key)) {
            return $this->indexes[$key];
        } else {
            return $this->indexes[$this->key()];
        }
    }

/// ArrayAccess interface
    public function offsetExists($offset) {
        $offsetExists = false;
        $hash = spl_object_hash($offset);
        if(isset($this->indexes[$hash]) &&
            isset($this->values[$hash])) {
            $offsetExists = true;
            $this->curOffset = $hash;
        }

        return $offsetExists;
    }

    public function offsetGet($offset) {
        if($this->offsetExists($offset)) {
            return $this->values[$this->curOffset];
        }
    }

    /**
     * note at this point it is assumed that $offset is an object
     */
    public function offsetSet($offset, $value) {
        if(!$this->offsetExists($offset)) { // grab index of offset
            /// set value of offset for first time
            $hash = spl_object_hash($offset);
            $this->indexes[$hash] = $offset;
            $this->values[$hash] = $value;
            $this->offsets[] = $hash;
            $this->totalElements++;
        } else {
            /// update value of offset
            $this->values[$this->curOffset] = $value;
        }
    }

    public function offsetUnset($offset) {
        if($this->offsetExists($offset)) {
            unset($this->indexes[$this->curOffset]);
            unset($this->values[$this->curOffset]);
            $this->totalElements--;
        }
    }

/// Iterator interface
    public function current() {
        return $this->values[$this->key()];
    }

    public function key() {
        return $this->offsets[$this->curOffsetNum];
    }

    public function next() {
        $this->curOffsetNum++;
    }

    public function rewind() {
        if($this->totalElements > 0) {
            $this->curOffsetNum = 0;
        } else {
            $this->curOffsetNum = -1;
        }
    }

    public function valid() {
        $isValid = false;
        if(isset($this->indexes[$this->offsets[$this->curOffsetNum]]) &&
            isset($this->values[$this->key()])) {
            $isValid = true;
        }
        return $isValid;
    }
}

$objArr = new ObjectArray();

/// make $a & $c the same so == comparison should succeed
$a = new StdClass();
$b = new StdClass();
$b->a = 'spl is the shit ;)';
$c = new stdClass();

// test putting a value in w/ object as index
$objArr[$a] = 5;
echo $objArr[$a] . PHP_EOL;
// test changing the value
$objArr[$a] = 6;
echo $objArr[$a] . PHP_EOL;
// note we can put in objs that pass == test, because internally
// we use ===
$objArr[$c] = 7;

echo 'count: ' . count($objArr) . PHP_EOL;
$objArr[$b] = 8;
echo 'count: ' . count($objArr) . PHP_EOL;

var_dump($objArr[$a] == $objArr[$b]); // false
var_dump($objArr[$a] == $objArr[$c]); // false

/// now working thanks to spl_object_hash()
foreach($objArr as $key => $val) {
    if($a === $objArr->keyVal()) {
        echo "keyFound: {$objArr[$a]}" . PHP_EOL;
        break;
    }
}
?>

-nathan

attached mail follows:


Casey wrote:
> On Mon, Mar 17, 2008 at 3:56 AM, Mikey <frakupcore.net> wrote:
>> Hi!
>>
>> I was wondering if anyone here had experienced a simliar problem to mine.
>>
>> I am updating an Oracle XMLType column with XML built using DOM that is
>> populated with values from an Excel spreadsheet saved out as a CSV.
>>
>> My problem is that for certain (apparently) random rows the xml updated
>> will fail with the error:
>>
>> Warning: oci_execute(): OCIStmtExecute: ORA-31011: XML parsing failed
>> ORA-19202: Error occurred in XML processing
>> LPX-00217: invalid character 0 (\u0000)
>> Error at line 1
>> ORA-06512: at "SYS.XMLTYPE", line 5
>> ORA-06512: at line 1
>> in /path/ob/fu/scated/archive.inc on line 1374
>>
>> I have googled around and a Java fix for the problem seemed to revolve
>> around a null char being left on the end of the XML string, so I tried
>> stripping the last char from the string but this did not help. I then
>> used an ordUTF8 function I found in the manual notes to see if I could
>> find the null in the string - again, no luck.
>>
>> So my question is whether or not anyone here has a reliable way of
>> detcting and removing \u0000 chars from strings?
>>
>> regards,
>>
>> Mikey
>>
>> --
>
> How about:
> $str = str_replace("\0", '', $str);
>
> -Casey

You would think wouldn't you? I even tried asc(0) to no avail.

Well, my problem for now has gone away as an ammended version of the
spreadsheet did not have these errors, but a weird one, without a doubt!

Mikey

attached mail follows:


what book would you guys suggest for someone who's new and wants to learn php?

--
http://alexus.org/

attached mail follows:


On Wed, Mar 19, 2008 at 10:50 AM, alexus <alexusgmail.com> wrote:
> what book would you guys suggest for someone who's new and wants to learn php?

    This is just my opinion, of course, but I wouldn't recommend
starting with a book. I'd recommend the online manual at
http://php.net/manual/ and jumping right in, head-first with writing
scripts and figuring out how to fix things when they break. Others
may recommend good printed material though.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


At 11:04 AM -0400 3/19/08, Daniel Brown wrote:
>On Wed, Mar 19, 2008 at 10:50 AM, alexus <alexusgmail.com> wrote:
>> what book would you guys suggest for someone who's new and wants
>>to learn php?
>
> This is just my opinion, of course, but I wouldn't recommend
>starting with a book. I'd recommend the online manual at
>http://php.net/manual/ and jumping right in, head-first with writing
>scripts and figuring out how to fix things when they break. Others
>may recommend good printed material though.

I'm sure we have a page somewhere that shows what tutorial links are
recommended. But here's a few I've used:

http://www.unf.edu/~rita0001/eresources/php_tutorials/index.htm
http://www.w3schools.com/php/default.asp
http://www.brainbell.com/tutors/php/php_mysql/index.html
http://www.tizag.com/phpT/
http://hudzilla.org/phpwiki/index.php?title=Main_Page

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


> On Wed, Mar 19, 2008 at 10:50 AM, alexus <alexusgmail.com> wrote:
> > what book would you guys suggest for someone who's new and
> wants to learn php?
>
> This is just my opinion, of course, but I wouldn't recommend
> starting with a book. I'd recommend the online manual at
> http://php.net/manual/ and jumping right in, head-first with writing
> scripts and figuring out how to fix things when they break. Others
> may recommend good printed material though.
>
> --
> </Daniel P. Brown>

I must agree with Dan's approach. I've messed with Frontier, ASP, Java and
PHP using this approach and it works for me. I always find that books just
miss out on that vital topic I need to work on.

Set up a small project (I'd recommend something database related) and look
for sample scripts in the manual and elsewhere.

Cheers

George

attached mail follows:


On Wed, Mar 19, 2008 at 11:51 AM, George Pitcher
<george.pitcheringenta.com> wrote:
>
> I must agree with Dan's approach. I've messed with Frontier, ASP, Java and
> PHP using this approach and it works for me. I always find that books just
> miss out on that vital topic I need to work on.

    I find that you're also going to be restricted to using the
author's methodology and preference if you follow a book, rather than
developing your own. It would be like telling a fine artist that his
painting technique is all wrong, and that there's only one real way of
doing the job. All of the paintings in the Louvre would look like
they were done by Disney.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


Hi gang:

I have a situation where users can purchase stuff online.

In the last step in the process, the user clicks a "confirm purchase"
button and their credit card is checked and if it's valid, they are
awarded the product. Everything works, but it takes a little time to
check the credit card.

During the time it takes to send the credit card information to the
clearing house and get back an "Ok" with a transaction ID, the user
can click the "confirm purchase" button more than once. As such, more
than one order can be made during the process.

I was thinking of using the database to prohibit multiple "confirm
purchase" clicks made by the user, but I wanted to ask this group if
anyone has a simpler idea/solution?

Thanks,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


On Wed, Mar 19, 2008 at 11:48 AM, tedd <teddsperling.com> wrote:

> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user
> can click the "confirm purchase" button more than once. As such, more
> than one order can be made during the process.
>
> I was thinking of using the database to prohibit multiple "confirm
> purchase" clicks made by the user, but I wanted to ask this group if
> anyone has a simpler idea/solution?
>
>
>
>
I had a similar problem with one of our applications here. I ended up
adding some javascript to disable the button once clicked, and then putting
in code in the php to prevent duplicates. It seemed to do the trick. I can
send over some sample code if you need. For the javascript I just made the
submit button hit a function, disable the button, then submit the form.

--
-Dan Joseph

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."

attached mail follows:


tedd wrote:
> I have a situation where users can purchase stuff online.
>
> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user can
> click the "confirm purchase" button more than once. As such, more than
> one order can be made during the process.
>
> I was thinking of using the database to prohibit multiple "confirm
> purchase" clicks made by the user, but I wanted to ask this group if
> anyone has a simpler idea/solution?

In the onclick for the button...

onclick="this.disabled=1;this.value='Processing, please wait...';"

You can also do this in the onsubmit of the form but you obviously need
to change this to a document.getElementById.

I'd also recommend you put some JS at the end of the page to enable the
button and set its value otherwise users hitting the back button may be
presented with a disabled button which is annoying.

-Stut

--
http://stut.net/

attached mail follows:


> Hi gang:
>
> I have a situation where users can purchase stuff online.
>
> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user
> can click the "confirm purchase" button more than once. As such, more
> than one order can be made during the process.
>
> I was thinking of using the database to prohibit multiple "confirm
> purchase" clicks made by the user, but I wanted to ask this group if
> anyone has a simpler idea/solution?
>
> Thanks,
>
> tedd

How about a bit of JavaScript that disabled the button when the form was
submitted? This is used by eBay and Google for their login processes.

Sure, if JS was disabled this could be circumvented but it would be a good
start and work with the majority of users.

Edward

attached mail follows:


> Hi gang:
>
> I have a situation where users can purchase stuff online.
>
> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user
> can click the "confirm purchase" button more than once. As such, more
> than one order can be made during the process.
>
> I was thinking of using the database to prohibit multiple "confirm
> purchase" clicks made by the user, but I wanted to ask this group if
> anyone has a simpler idea/solution?
>
> Thanks,
>
> tedd

Oh, I'd also add a bit of text near the button saying:

"Please click this button ONCE only. Clicking again may result in your
credit card being billed twice."

I'm always much more precise with my clicking when such warnings are
displayed :)

Edward

attached mail follows:


On Wed, Mar 19, 2008 at 11:48 AM, tedd <teddsperling.com> wrote:
> Hi gang:
>
> I have a situation where users can purchase stuff online.
>
> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user
> can click the "confirm purchase" button more than once. As such, more
> than one order can be made during the process.
>
> I was thinking of using the database to prohibit multiple "confirm
> purchase" clicks made by the user, but I wanted to ask this group if
> anyone has a simpler idea/solution?
>
> Thanks,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Unique form tokens.

Generate a token when the form is displayed and save that value in the session.

Then on post check it and remove it. Then if they re-submit it will
not exist therefore be invalid.

attached mail follows:


On Wed, Mar 19, 2008 at 11:48 AM, tedd <teddsperling.com> wrote:
> Hi gang:
>
> I have a situation where users can purchase stuff online.
>
> In the last step in the process, the user clicks a "confirm purchase"
> button and their credit card is checked and if it's valid, they are
> awarded the product. Everything works, but it takes a little time to
> check the credit card.
>
> During the time it takes to send the credit card information to the
> clearing house and get back an "Ok" with a transaction ID, the user
> can click the "confirm purchase" button more than once. As such, more
> than one order can be made during the process.

    I'd use a JavaScript onClick event to disable the button, but I'd
back it up with a timestamp tracker to compare clicks of the button.
If someone clicks the button and, for whatever reason, the script
times-out, they'll probably try to order again. No sweat. The
timestamp tracker can verify that the order was not successful within
(n) (duration), and if one is found within said duration, the user is
shown a message stating that their order has already been processed,
with an option to purchase the item again if that was their intent.
If there wasn't a successful response from the payment processor, the
timestamp isn't recorded, and the purchase can go through as expected.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


On Wed, Mar 19, 2008 at 12:01 PM, Eric Butera <eric.buteragmail.com> wrote:
>
> Unique form tokens.
>
> Generate a token when the form is displayed and save that value in the session.
>
> Then on post check it and remove it. Then if they re-submit it will
> not exist therefore be invalid.

    I like Eric's method better than the timestamp method I proposed.
Much cleaner and easier to institute, and I'd hazard a guess at it
being more reliable as well.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


At 4:00 PM +0000 3/19/08, Edward Kay wrote:
>Oh, I'd also add a bit of text near the button saying:
>
>"Please click this button ONCE only. Clicking again may result in your
>credit card being billed twice."
>
>I'm always much more precise with my clicking when such warnings are
>displayed :)

That's already in place. But people have a hard time reading when
their fingers are clicking.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


tedd wrote:
// ...

Your first (and the quickest by far) method to employ would be to
disable the submit button using Jabbascript when the form is submitted.
That will stop the vast majority of occurrences. You could also employ
an intermediary page which actually does the card processing and when
complete redirects to the "thank you" page. ie.

    Form --> "Please wait..." page --> "Thank you" page

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

attached mail follows:


At 4:19 PM +0000 3/19/08, Richard Heyes wrote:
>tedd wrote:
>// ...
>
>Your first (and the quickest by far) method to employ would be to
>disable the submit button using Jabbascript when the form is
>submitted. That will stop the vast majority of occurrences. You
>could also employ an intermediary page which actually does the card
>processing and when complete redirects to the "thank you" page. ie.
>
> Form --> "Please wait..." page --> "Thank you" page

That's in place. The person clicks the "confirm purchase" and they
are taken to a "confirm and thank you page".

The problem here is two fold -- 1) clicking the "confirm
purchase"button twice, which I think js will stop; 2) and clicking
the back-button which the token should stop.

Now, I just need to develop a test for this. Sometime writing a test
is more of a problem than writing the solution.

Thanks for everyone's help.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


Daniel Brown wrote:
> On Wed, Mar 19, 2008 at 12:01 PM, Eric Butera <eric.buteragmail.com> wrote:
>> Unique form tokens.
>>
>> Generate a token when the form is displayed and save that value in the session.
>>
>> Then on post check it and remove it. Then if they re-submit it will
>> not exist therefore be invalid.
>
> I like Eric's method better than the timestamp method I proposed.
> Much cleaner and easier to institute, and I'd hazard a guess at it
> being more reliable as well.
>

The initial problem that I see with it would be that if the user clicks the
submit button a second time, the first transaction is canceled. If the process
takes a long time, maybe the time period for the server to get the approval has
already passed, but the server is still doing stuff but not redirected the
person to the success page. At this point, the user has purchased the item
successfully, but they did see the success page. So they repeat the process,
over and over and over...

That is a situation that I can envision at least.

My suggestion would be to disable the submit button. This would prevent the
first transaction from being killed prematurely.

--
Jim Lucas

    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
     by William Shakespeare

attached mail follows:


On Wed, Mar 19, 2008 at 12:44 PM, Jim Lucas <listscmsws.com> wrote:
> Daniel Brown wrote:
> >
> > I like Eric's method better than the timestamp method I proposed.
> > Much cleaner and easier to institute, and I'd hazard a guess at it
> > being more reliable as well.
> >
>
> The initial problem that I see with it would be that if the user clicks the
> submit button a second time, the first transaction is canceled. If the process
> takes a long time, maybe the time period for the server to get the approval has
> already passed, but the server is still doing stuff but not redirected the
> person to the success page. At this point, the user has purchased the item
> successfully, but they did see the success page. So they repeat the process,
> over and over and over...

    Right, but I meant that as a replacement to my "backup" solution.
As a backup for disabling the button using JavaScript, as mentioned.

    Sorry, should've clarified that. Good catch, Jim.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


Hi,

I am working in page breaking (dividing the result of
a select query in multiple pages).

Now my problem is not with the php code, but with the
algorithm that organize the links to the pages. I want
to do something like google, the pages numbers at the
bottom of the page must not exceed a maximum number,
the actual page must be in the center of the links to
other pages and there are a lot of other conditions
that arise.

Do you know about a site that describe these
conditions or may be propose the whole algorithm for
that?

Thank you

      ____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping

attached mail follows:


On Wed, Mar 19, 2008 at 12:01 PM, It Maq <itmaqurfeyahoo.com> wrote:
> Hi,
>
> I am working in page breaking (dividing the result of
> a select query in multiple pages).

    It's more commonly referred to as "pagination." You'll get more
accurate results with the proper terminology.

> Now my problem is not with the php code, but with the
> algorithm that organize the links to the pages. I want
> to do something like google, the pages numbers at the
> bottom of the page must not exceed a maximum number,
> the actual page must be in the center of the links to
> other pages and there are a lot of other conditions
> that arise.

    If I'm understanding you correctly, all you'll need are a few
if/else conditions, some range math, and some LIMIT conditions in your
SQL query.

> Do you know about a site that describe these
> conditions or may be propose the whole algorithm for
> that?

    STFW. ;-P

    http://www.google.com/search?q=php+pagination+like+Google

    The top two results look like they hit the nail right on the head for you.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


At 9:01 AM -0700 3/19/08, It Maq wrote:
>I am working in page breaking (dividing the result of
>a select query in multiple pages).
>
>Now my problem is not with the php code, but with the
>algorithm that organize the links to the pages. I want
>to do something like google, the pages numbers at the
>bottom of the page must not exceed a maximum number,
>the actual page must be in the center of the links to
>other pages and there are a lot of other conditions
>that arise.
>
>Do you know about a site that describe these
>conditions or may be propose the whole algorithm for
>that?

Hi Maq:

I think this might help.

http://webbytedd.com/bbb/paging/index.php?page=1

The code for it is there.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


> Hi,
>
> I am working in page breaking (dividing the result of
> a select query in multiple pages).
>
> Now my problem is not with the php code, but with the
> algorithm that organize the links to the pages. I want
> to do something like google, the pages numbers at the
> bottom of the page must not exceed a maximum number,
> the actual page must be in the center of the links to
> other pages and there are a lot of other conditions
> that arise.
>
> Do you know about a site that describe these
> conditions or may be propose the whole algorithm for
> that?
>
> Thank you
>
>

http://www.google.co.uk/search?q=pagination+php

attached mail follows:


Hi,

I'm trying to resolve an issue with a pagination routine. Sounds like we're
working on a similar routine. I have a query returning products from a
database and then display the results in a defined number of products per
page.

Checkout - 'Newbie question, Which way is best?' in this newsgroup.

George

attached mail follows:


On Thu, Mar 20, 2008 at 7:35 AM, George J <georgejamiesonbtconnect.com>
wrote:

> Hi,
>
> I'm trying to resolve an issue with a pagination routine. Sounds like
> we're
> working on a similar routine. I have a query returning products from a
> database and then display the results in a defined number of products per
> page.
>
> Checkout - 'Newbie question, Which way is best?' in this newsgroup.
>
> George
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> i have spent some time to figure it out last time. i did create a simple
function to do it
total - is the total record. can be output of SELECT COUNT(*) FROM table
offset - is the current offset.

    //display pages
    function pages($total, $offset, $perpage)
       {
           if($total == 0) return;

           $total_pages = floor($total / $perpage);
           $current_page = floor($offset / $perpage);

           $pg = '';
           for($i = 0; $i <= $total_pages; $i++)
           {
               $pg .= "<a class='page_nav' href='?p=".($i *
$perpage)."'>".($i + 1)."</a>";
        }

        return $pg;
    }

i am afraid this one look too simple. but you can see how the basis work.
this one simply print 1, 2, 3 etc..

attached mail follows:


i know it is forbidden to sell open source software.

let say i have costumer want me to modified an open source php script.
i have the right to charge him the service to modified the software.

but this costumer ask me to do one thing against the gpl software.
he want me to remove all the link and powered by link (anything visible to
the end user)

what should i do to satisfy my costumer without making myself against
the spirit of open source community?

attached mail follows:


jeffry s wrote:
> i know it is forbidden to sell open source software.
>
> let say i have costumer want me to modified an open source php script.
> i have the right to charge him the service to modified the software.
>
> but this costumer ask me to do one thing against the gpl software.
> he want me to remove all the link and powered by link (anything visible to
> the end user)
>
> what should i do to satisfy my costumer without making myself against
> the spirit of open source community?

Don't do it. It has nothing to do with "the spirit of the community",
it's (potentially[1]) breaking the law. Contact the maintainer of the
software to find out if there's a way to get it under a different
license. If not look for an alternative that meets the customers
requirements.

-Stut

[1] Yet to be sufficiently tested in court in most countries, but do you
really want to take the risk?!

--
http://stut.net/

attached mail follows:


jeffry s wrote:
> i know it is forbidden to sell open source software.

Er, no it's not.

> let say i have costumer want me to modified an open source php script.
> i have the right to charge him the service to modified the software.

Of course.

> but this costumer ask me to do one thing against the gpl software.
> he want me to remove all the link and powered by link (anything visible to
> the end user)

Which you can do (IIRC).

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

attached mail follows:


On Wed, Mar 19, 2008 at 12:11 PM, jeffry s <paragasugmail.com> wrote:
> i know it is forbidden to sell open source software.

    That's your first mistake. It may be unethical and frowned upon
by the community-at-large, but nearly all open source licenses
(including GPL) allow for the code to be sold. From GPLv3:

       "You may charge any price or no price for each copy that you
convey, and you may offer support or warranty protection for a fee."

> let say i have costumer want me to modified an open source php script.
> i have the right to charge him the service to modified the software.

    That is correct by all means, because you're charging a fee for a
service, not a fee for someone else's work or derivatives.

> but this costumer ask me to do one thing against the gpl software.
> he want me to remove all the link and powered by link (anything visible to
> the end user)

    GPL doesn't explicitly require that. That would be licensing by
the individual project.

> what should i do to satisfy my costumer without making myself against
> the spirit of open source community?

    Quite honestly, if your client is willing to pay for removal of
the links, you should work with the original author(s) to determine
the value of the script(s) you'll be using and request a commercial
license. In so doing, you're not only abiding by all of the written
and unwritten laws of the community, but also supporting a project
financially --- which is ALWAYS welcome.

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


umm...

if the author of the app has included terms saying that you can use the app,
provided that you keep the links/etc... then no, you can't violate the
terms... however, in reality, of course people do it all the time...

the single guy, or a few guys who are working on an open source app, aren't
going to have the resources to try and track down these situations...

but as far as selling the code, if the code is "gpl" you can sell it,
provided you also make the source code available to the end user if they
want it...

peace..

-----Original Message-----
From: Richard Heyes [mailto:richardhphpguru.org]
Sent: Wednesday, March 19, 2008 8:23 AM
To: jeffry s
Cc: PHP General list
Subject: Re: [PHP] selling gpl software?

jeffry s wrote:
> i know it is forbidden to sell open source software.

Er, no it's not.

> let say i have costumer want me to modified an open source php script.
> i have the right to charge him the service to modified the software.

Of course.

> but this costumer ask me to do one thing against the gpl software.
> he want me to remove all the link and powered by link (anything visible to
> the end user)

Which you can do (IIRC).

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

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

attached mail follows:


At 12:11 AM +0800 3/20/08, jeffry s wrote:
>i know it is forbidden to sell open source software.
>
>let say i have costumer want me to modified an open source php script.
>i have the right to charge him the service to modified the software.
>
>but this costumer ask me to do one thing against the gpl software.
>he want me to remove all the link and powered by link (anything visible to
>the end user)
>
>what should i do to satisfy my costumer without making myself against
>the spirit of open source community?

This comes down to what you can live with. Only you can answer that.

I do not sit in judgement regarding anything a client wants. But,
there are some things I won't do, like pornography, or spam, or any
illegal activity because I don't want the liability exposure that
accompanies it.

My advice, if it's illegal, then don't do it.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


> if the author of the app has included terms saying that you can use the app,
> provided that you keep the links/etc... then no, you can't violate the
> terms... however, in reality, of course people do it all the time...

Then it wouldn't be under the GPL. The GPL is itself a set of terms that
grant you permission to use and redistribute the software. If you add to
it, it stops being the GPL.

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

attached mail follows:


jeffry s wrote:
> i know it is forbidden to sell open source software.

Actually, you can sell GPL software. But that's not the point here.
Persumably the client knows all about it and knows it exists and
"selling" it per-se is not the important part here.

> let say i have costumer want me to modified an open source php script.
> i have the right to charge him the service to modified the software.

Certainly this is indeed your right.

> but this costumer ask me to do one thing against the gpl software.
> he want me to remove all the link and powered by link (anything visible to
> the end user)

That's nothing to do with the GPL. The author may put terms of use out
there, but removing the links produced by the code is just the same as
any other modification. Sure, it doesn't feel right, but in theory there
is nothing wrong with this.

> what should i do to satisfy my costumer without making myself against
> the spirit of open source community?

I'd suggest that you ask your client to reconsider the attribution links
or perhaps agree to a toned down version of them.

Also as it's GPL and as you are "supplying" the modifications you make
to your client, you are obliged to release the changes you make to the
community. If this was a 100% internal development (e.g. you are
employed directly by your client, not as a contractor), then you are not
obliged to release the changes.

Releasing the changes would certainly be within the spirit of the GPL
and the community.

IANAL so apologies if I've gotten anything wrong here.

Col

attached mail follows:


On Wed, Mar 19, 2008 at 12:55 PM, Colin Guthrie <gmanecolin.guthr.ie> wrote:
>
> IANAL so apologies if I've gotten anything wrong here.

    Yes, we know you're anal. ;-P

    In all seriousness, looks like you got it all right. +1 for you
(and a gold star)!

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


richard...

sure it would!! you can easily have gpl software, and then apply additional
copyright/use terms. as long as your additional conditions don't obviate, or
change the gpl, then you're fine...

peace..

-----Original Message-----
From: Richard Heyes [mailto:richardhphpguru.org]
Sent: Wednesday, March 19, 2008 8:42 AM
To: bruce
Cc: 'jeffry s'; 'PHP General list'
Subject: Re: [PHP] selling gpl software?

> if the author of the app has included terms saying that you can use the
app,
> provided that you keep the links/etc... then no, you can't violate the
> terms... however, in reality, of course people do it all the time...

Then it wouldn't be under the GPL. The GPL is itself a set of terms that
grant you permission to use and redistribute the software. If you add to
it, it stops being the GPL.

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

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

attached mail follows:


On Thu, Mar 20, 2008 at 1:02 AM, Daniel Brown <parasanegmail.com> wrote:

> On Wed, Mar 19, 2008 at 12:55 PM, Colin Guthrie <gmanecolin.guthr.ie>
> wrote:
> >
> > IANAL so apologies if I've gotten anything wrong here.
>
> Yes, we know you're anal. ;-P
>
> In all seriousness, looks like you got it all right. +1 for you
> (and a gold star)!
>
> --
> </Daniel P. Brown>
> Forensic Services, Senior Unix Engineer
> 1+ (570-) 362-0283
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

well, i am quite surprised with you all feedback.
then it is ok to remove all the link as part of modification then as long
as the source code available to the client (it is php script anyway)

forgive me for my stupidness. i am quite confuse with law thing
and gpl, gplv2 and gplv3 or gnu proven hard for me to understand.
anyone can point me a comparison between all this?

a simple explanation easy for baby to digest.. :)

attached mail follows:


On Wed, Mar 19, 2008 at 1:13 PM, jeffry s <paragasugmail.com> wrote:
>
> forgive me for my stupidness. i am quite confuse with law thing
> and gpl, gplv2 and gplv3 or gnu proven hard for me to understand.
> anyone can point me a comparison between all this?

    GPL is the (GNU) General Public License.

    GPLv2/GPLv3 are the second/third versions, containing
modifications, ratifications, and clarifications. There may be some
other ifications in there that I'm forgetting as well.

    GNU is a recursive acronym (as PHP now is for PHP Hypertext
Preprocessor). It stands for GNU's Not Unix, and is an operating
system. It's often confused with the organization from which it
receives primary focus (and shares the founder: Richard Stallman),
known as the FSF - the Free Software Foundation.

> a simple explanation easy for baby to digest.. :)

    Now go get burped and have Mommy change your diaper. ;-P

--
</Daniel P. Brown>
Forensic Services, Senior Unix Engineer
1+ (570-) 362-0283

attached mail follows:


On Thu, Mar 20, 2008 at 1:19 AM, Daniel Brown <parasanegmail.com> wrote:

> On Wed, Mar 19, 2008 at 1:13 PM, jeffry s <paragasugmail.com> wrote:
> >
> > forgive me for my stupidness. i am quite confuse with law thing
> > and gpl, gplv2 and gplv3 or gnu proven hard for me to understand.
> > anyone can point me a comparison between all this?
>
> GPL is the (GNU) General Public License.
>
> GPLv2/GPLv