php-general Digest 16 Feb 2002 13:34:08 -0000 Issue 1175

Topics (messages 84990 through 85029):

Re: The ASP "application" object in PHP?
        84990 by: Michael Sims
        84994 by: Tom Rogers
        84995 by: michael kimsal
        84997 by: Joshua Hoover
        84998 by: Tom Rogers
        85004 by: Peter J. Schoenster
        85029 by: michael kimsal

Re: scheduled tasks
        84991 by: Michael Sims

PHP phone consultations  :)
        84992 by: michael kimsal

extract nouns
        84993 by: Heiko Spallek

modular programming
        84996 by: Kunal Jhunjhunwala
        85001 by: Steven Walker
        85003 by: Kunal Jhunjhunwala
        85005 by: Eugene Lee
        85006 by: Peter Janett
        85016 by: DL Neil
        85019 by: Kunal Jhunjhunwala
        85028 by: DL Neil

Re: COOKIE HEADER????
        84999 by: Michael Sims

suscribir
        85000 by: MAURICIO

Sessions and templating help
        85002 by: Justin Deutsch

Outputing XML to browser???
        85007 by: Jim Hankins

vpopmail Functions
        85008 by: Pete Bekisz
        85011 by: Jason Wong

Is there an MSSQL limit function?
        85009 by: Dean Householder
        85010 by: Jason Wong
        85012 by: Dean Householder
        85013 by: Jason Wong
        85014 by: Dean Householder
        85015 by: Michael Sims

Problem in a user auth script. Advice please.
        85017 by: Matthew Darcy

user auth script update.
        85018 by: Matthew Darcy
        85021 by: Matt
        85025 by: Matthew Darcy

not really a php question but can't hurt to ask.
        85020 by: Matthew Darcy
        85023 by: Matthew Darcy
        85024 by: Matt

Generating PDF documents
        85022 by: Alberto Pirovano

zipping files on the fly
        85026 by: Kunal Jhunjhunwala

Sessions that last for ever
        85027 by: Nigel Gilbert

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
At 02:21 PM 2/15/2002 -0500, Michael Kimsal wrote:
>I've been here all along!  :)
>
>Seriously, we cover some of this in our class as well, and at our monthly 
>PHP user group meetings.  I'm actually writing up a small paper
>on this and other topics.  If you're interested in it, let me know.
>
>I can also be reached at 734-480-9961 if you've questions that might
>be faster talking about than emailing, and my AIM is 'mgkimsal' is you're 
>on that and need some help.
>
>That goes for anyone else on the list too...

OMG you may end up regretting that.  I'm putting you on my speed dial right 
now... :-P  Yeah, it's not toll-free but as They say "it's free if you call 
from work"

--- End Message ---
--- Begin Message ---
Hi
It uses cookies and only cookies and it seems that sessions are started on 
every access but can be turned off on individual pages if required.
Tom


At 07:44 AM 2/16/02, Peter J. Schoenster wrote:
>On 15 Feb 2002, at 14:43, Bendik Simonsen wrote:
>
>
> > I have however, noticed one feature that ASP has that I have not found
> > an equal for in PHP: the "application" object.
> >
> > For those of you not familiar with ASP, the lowdown is this: The
> > application object acts like a global session. You assign it variables
> > and values like you would a session, but those variables are available
> > to all instances and sessions. It is for example very useful to track
> > different users at the same time, or to send messages from one session
> > to another, or the likes.
> >
> > Anything like this in PHP, or will I have to find a workaround for it,
> > or *ick* do that little sniplet in ASP?
>
>Well how does it work? Is it advertised as M$ magic in the class?
>Is http not stateless?
>
>I don't follow your description and I don't believe in magic.
>
>Is it using cookies? If not what? It must be using something?
>
>I bet it's using cookies. Sounds a lot like what you normally do with
>sessions. I don't follow the "send message from one session to
>another" ... is this not just normal course for sessions?  I'd like
>more explanation before I believe that this is any more than just a
>module.
>
>Peter
>http://www.readbrazil.com/
>Answering Your Questions About Brazil
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Tom Rogers wrote:
> Hi
> It uses cookies and only cookies and it seems that sessions are started 
> on every access but can be turned off on individual pages if required.
> Tom
> 


Sorry Tom, but the application object has nothing to do with cookies. 
It is a 'global' session, for lack of a better term, and doesn't need to
concern itself with cookies or other means of identifying specific 
users, because nothing in the application object is specific to users - 
it is data specific to the total application itself.

You may be thinking of sessions themselves - the 'session' object and 
the 'application' object are treated similarly from a programmatic 
standpoint but are pretty different underneath in terms of operation and 
purpose.

Hope that helps.

Michael Kimsal
http://www.tapinternet.com/php
PHP training courses
734-480-9961


--- End Message ---
--- Begin Message ---
One way to simulate an application object is to use the php.ini
"auto_prepend_file" option.  Set the file with your application variables to
be the file you want to prepend to every file in your application.  Now, the
only part that you don't have is an easy way to add/update/delete these
variables.  I suppose you could write a fairly simple class that allowed you
to manipulate the file line by line, which would essentially give you access
to all the variables for add/update/delete functionality.

I use "auto_prepend_file" quite a bit for my applications and it acts just
like an application object.  I haven't found a time where I need/want to
manipulate the variables "on the fly" within code.  Most of the variables
being set are simply configuration settings for the application, not
variables needing to change and be shared across the application.

Hope that helps some,

Joshua Hoover


> > For those of you not familiar with ASP, the lowdown is this: The
> > application object acts like a global session. You assign it variables
> > and values like you would a session, but those variables are available
> > to all instances and sessions. It is for example very useful to track
> > different users at the same time, or to send messages from one session
> > to another, or the likes.



--- End Message ---
--- Begin Message ---
Hi
Yes you are right ... i had my head tied up with sessions :)
Tom

At 02:12 PM 2/16/02, michael kimsal wrote:
>Tom Rogers wrote:
>>Hi
>>It uses cookies and only cookies and it seems that sessions are started 
>>on every access but can be turned off on individual pages if required.
>>Tom
>
>
>Sorry Tom, but the application object has nothing to do with cookies. It 
>is a 'global' session, for lack of a better term, and doesn't need to
>concern itself with cookies or other means of identifying specific users, 
>because nothing in the application object is specific to users - it is 
>data specific to the total application itself.
>
>You may be thinking of sessions themselves - the 'session' object and the 
>'application' object are treated similarly from a programmatic standpoint 
>but are pretty different underneath in terms of operation and purpose.
>
>Hope that helps.
>
>Michael Kimsal
>http://www.tapinternet.com/php
>PHP training courses
>734-480-9961
>
>

--- End Message ---
--- Begin Message ---
On 15 Feb 2002, at 23:12, michael kimsal wrote:

> Tom Rogers wrote:
> > Hi
> > It uses cookies and only cookies and it seems that sessions are
> > started on every access but can be turned off on individual pages if
> > required. Tom
> 
> Sorry Tom, but the application object has nothing to do with cookies.
> It is a 'global' session, for lack of a better term, and doesn't need
> to concern itself with cookies or other means of identifying specific
> users, because nothing in the application object is specific to users
> - it is data specific to the total application itself.

> Hope that helps.

The original guy wrote:

> > > to all instances and sessions. It is for example very useful to
> > > track different users at the same time, or to send messages from
> > > one session to another, or the likes.

Well it started from the above where some guy said this magic 
could track users. I assumed the cookies and if it's tracking users 
it uses a session id in the url or a cookie, I know of no other way 
and would really appreciate the education.

> Tom Rogers wrote:

> - it is data specific to the total application itself.

But how does it carry from one click to the next?

Peter


http://www.readbrazil.com/
Answering Your Questions About Brazil
--- End Message ---
--- Begin Message ---
Peter J. Schoenster wrote:

> 
>>>>to all instances and sessions. It is for example very useful to
>>>>track different users at the same time, or to send messages from
>>>>one session to another, or the likes.
>>>>
> 
> Well it started from the above where some guy said this magic 
> could track users. I assumed the cookies and if it's tracking users 
> it uses a session id in the url or a cookie, I know of no other way 
> and would really appreciate the education.
> 
> 
>>Tom Rogers wrote:
>>
> 
>>- it is data specific to the total application itself.
>>
> 
> But how does it carry from one click to the next?
> 


I don't believe the original poster you quote really had/has
a firm grasp on what it actually does.

The tried and true example is a hit counter.  No matter who hits a page,
if that page increases an application variable called "counter" for 
example, the counter keeps going up.

You hit it and it has a value of 1.
Then I hit the page and it has a value of 2.
The bob hits it and it has a value of 3.

And so on.

There's no messaging from one session to another, though I don't doubt
you could architect some code to operate like that.  It's like a 
'session' state that's not specific to any one user - a 'commons' area,
if you like.

Does that help?

Also, a second draft of this info, along with a bit of code example in 
PHP, is in a PDF at

http://demo.logicreate.com/index.php/filemgt/main/event=view/pkey=6/phpfaq.pdf


--- End Message ---
--- Begin Message ---
At 10:03 AM 2/15/2002 -1000, Rodney Davis wrote:
>Is currently anyway of doing scheduled tasks with PHP (without using
>crontab)?  For example, using an email script to send out e-mail
>reminders every Monday or something like that?

What's wrong with using cron?

--- End Message ---
--- Begin Message ---
Michael Sims wrote:
>> I can also be reached at 734-480-9961 if you've questions that might
>> be faster talking about than emailing, and my AIM is 'mgkimsal' is 
>> you're on that and need some help.
>>
>> That goes for anyone else on the list too...
> 
> OMG you may end up regretting that.  I'm putting you on my speed dial 
> right now... :-P  Yeah, it's not toll-free but as They say "it's free if 
> you call from work"

Hi Michael:

Not to turn this into too much of a sales pitch, but... :)

1.  We do offer hourly consulting for one-offs, so if you're in a pinch
and just HAVE to get something done, we can help.  Many times
you only need a small push in the right direction, not entire 
outsourcing of a project.

2.  That doesn't mean that every call is charged.  Got a question?  Give 
a call in.  I'm normally pretty open to discuss PHP and web matters, and
often can spare some time to help through problems - that's what we do 
at our monthly PHP user group meeting, and on the user group mailing 
list (sempug at yahoo groups!).  However, realize that I (or others at 
the office) might not be able to sit down and chat for hours at a 
stretch gratis.  :)

Don't let that put you off calling if you've got questions - often times 
questions that can have you stumped are things that we (or others) have 
faced in the past and solved already.

Michael Kimsal
http://www.tapinternet.com/php
PHP Training Courses
734-480-9961


--- End Message ---
--- Begin Message ---
Hi,

I am looking for some non-fancy language processing: I just want to
extract all nouns from a free text.

Is there anything available doing this. I guess it needs to have a
dictionary as part of the solution, but I don't know.

Thanks for suggestions!

Heiko


--- End Message ---
--- Begin Message ---
hey,
does anyone know of any good papers on modular programing? I have been able
to make my code modular, but I am not satisfied with it. I am trying to make
my program work the "plug in" way.. where i can just add more modules on the
fly... any tips? :)
Regards,
Kunal Jhunjhunwala

"Minds think with ideas, not information. No amount of data, bandwidth, or
processing power can substitute for inspired thought." - Clifford Stoll

--- End Message ---
--- Begin Message ---
Dear Kunal,

I don't know of any papers... I'd be interested in what you find.

In my experience, 'modular coding' is entirely a process of evolution. 
It's impossible to sit down and design software on paper. Every piece of 
code I write is under constant evaluation. Each time a weakness is 
exposed, I rethink my strategy. Often there is no 'perfect' solution, 
since each presents a different set of compromises. Devoting yourself to 
endlessly rewriting and structuring your code will, in the long term, 
yield better code than anyone can advise in a book or paper.

Over modulation of code has drawbacks too. Sometimes the simple solution 
is the one to use, even if it means rewriting the same thing every once 
in a while. When people start creating classes and polymorphic 
interfaces to their code needlessly, performance is compromised.

Perhaps what you are looking for is also a reference for good 
programming practice. For C++, I really liked the books by Scott Meyers: 
'Effective C++', first and second edition. Here he sets out some 
fundamental 'guidelines' for coding. You may like to check it out, even 
thought it doesn't apply to PHP directly.

Of what it's worth, that's my two cents :) I'd be interested in what 
others think on this matter.

Steven J. Walker
Walker Effects
www.walkereffects.com
[EMAIL PROTECTED]

On Friday, February 15, 2002, at 08:24  PM, Kunal Jhunjhunwala wrote:

> hey,
> does anyone know of any good papers on modular programing? I have been 
> able
> to make my code modular, but I am not satisfied with it. I am trying to 
> make
> my program work the "plug in" way.. where i can just add more modules 
> on the
> fly... any tips? :)
> Regards,
> Kunal Jhunjhunwala
>
> "Minds think with ideas, not information. No amount of data, bandwidth, 
> or
> processing power can substitute for inspired thought." - Clifford Stoll
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi,
I agree with everything you have said, it will come with evolution of the
program. But there are times, when evolution may require re-coding over
10,000lines of code. Not a very good place to be in then :)

So, if I started right, i would end and evolve right.. know what i mean?
Regards,
Kunal Jhunjhunwala

"Minds think with ideas, not information. No amount of data, bandwidth, or
processing power can substitute for inspired thought." - Clifford Stoll
----- Original Message -----
From: "Steven Walker" <[EMAIL PROTECTED]>
To: "Kunal Jhunjhunwala" <[EMAIL PROTECTED]>
Cc: "php-list" <[EMAIL PROTECTED]>
Sent: Saturday, February 16, 2002 11:11 AM
Subject: Re: [PHP] modular programming


> Dear Kunal,
>
> I don't know of any papers... I'd be interested in what you find.
>
> In my experience, 'modular coding' is entirely a process of evolution.
> It's impossible to sit down and design software on paper. Every piece of
> code I write is under constant evaluation. Each time a weakness is
> exposed, I rethink my strategy. Often there is no 'perfect' solution,
> since each presents a different set of compromises. Devoting yourself to
> endlessly rewriting and structuring your code will, in the long term,
> yield better code than anyone can advise in a book or paper.
>
> Over modulation of code has drawbacks too. Sometimes the simple solution
> is the one to use, even if it means rewriting the same thing every once
> in a while. When people start creating classes and polymorphic
> interfaces to their code needlessly, performance is compromised.
>
> Perhaps what you are looking for is also a reference for good
> programming practice. For C++, I really liked the books by Scott Meyers:
> 'Effective C++', first and second edition. Here he sets out some
> fundamental 'guidelines' for coding. You may like to check it out, even
> thought it doesn't apply to PHP directly.
>
> Of what it's worth, that's my two cents :) I'd be interested in what
> others think on this matter.
>
> Steven J. Walker
> Walker Effects
> www.walkereffects.com
> [EMAIL PROTECTED]
>
> On Friday, February 15, 2002, at 08:24  PM, Kunal Jhunjhunwala wrote:
>
> > hey,
> > does anyone know of any good papers on modular programing? I have been
> > able
> > to make my code modular, but I am not satisfied with it. I am trying to
> > make
> > my program work the "plug in" way.. where i can just add more modules
> > on the
> > fly... any tips? :)
> > Regards,
> > Kunal Jhunjhunwala
> >
> > "Minds think with ideas, not information. No amount of data, bandwidth,
> > or
> > processing power can substitute for inspired thought." - Clifford Stoll
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--- End Message ---
--- Begin Message ---
On Sat, Feb 16, 2002 at 09:54:40AM +0530, Kunal Jhunjhunwala wrote:
: 
: does anyone know of any good papers on modular programing? I have been able
: to make my code modular, but I am not satisfied with it. I am trying to make
: my program work the "plug in" way.. where i can just add more modules on the
: fly... any tips? :)

You're talking about a nice, OO framework.  Outside of university
computer science ivory tower environments like Smalltalk, and besides
NeXTSTEP/OPENSTEP/Cocoa of Mac OS X, your best bet is to make more OO
classes and learn to abstract consistent pieces.  Try taking a look at
"Design Patterns: Elements of Reusable Object-Oriented Software" by
Gamma, Helm, Johnson, Vlissides.

Also, from the ColdFusion world, there are framework architectures like
Fusebox whose concepts are supposed to be language-independent.


-- 
Eugene Lee
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
Check out http://www.Fusebox.org.  Fusebox is a programming methodology,
originally written for Cold Fusion.  Don't let the Cold Fusion scare you,
it's really not about the language, but rather it's about modular
programming, and may be exactly what you are looking for.  Once you get what
the methodology is about, you can go the site dedicated to Fusebox with PHP,
http://bombusbee.com.

There is a whole "Fusebox Community", which is built around the methodology.
Pretty good stuff, will save lots of time.

HTH,

Peter Janett

New Media One Web Services
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
New Upgrades Are Now Live!!!
Windows 2000 accounts - Cold Fusion 5.0 and Imail 7.1
Sun Solaris (UNIX) accounts - PHP 4.0.6, mod_perl/1.25,
Stronghold/3.0 (Apache/1.3.22), MySQL 3.23.43
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PostgreSQL coming soon!

http://www.newmediaone.net
[EMAIL PROTECTED]

----- Original Message -----
From: "Kunal Jhunjhunwala" <[EMAIL PROTECTED]>
To: "php-list" <[EMAIL PROTECTED]>
Sent: Friday, February 15, 2002 9:24 PM
Subject: [PHP] modular programming


> hey,
> does anyone know of any good papers on modular programing? I have been
able
> to make my code modular, but I am not satisfied with it. I am trying to
make
> my program work the "plug in" way.. where i can just add more modules on
the
> fly... any tips? :)
> Regards,
> Kunal Jhunjhunwala
>
> "Minds think with ideas, not information. No amount of data, bandwidth, or
> processing power can substitute for inspired thought." - Clifford Stoll
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Dear Steven and Kunal,
Agreed with what you had to say.

> In my experience, 'modular coding' is entirely a process of evolution.
> It's impossible to sit down and design software on paper. Every piece of
> code I write is under constant evaluation. Each time a weakness is
> exposed, I rethink my strategy. Often there is no 'perfect' solution,
> since each presents a different set of compromises. Devoting yourself to
> endlessly rewriting and structuring your code will, in the long term,
> yield better code than anyone can advise in a book or paper.

This para gives an impression that modular programming is an iterative process (maybe 
not Steven's intention).
An iterative approach would certainly enable you to improve the quality of your code - 
at some expense to
rethink/re-implement, and such improvements may well occur through changes to the 
modularisation/interfaces
between modules. Modular programming as a philosophy though, starts at the program 
design stage, not at version
two!

'Modular programming' as a concept is quite old (in computer/doggie years). Then there 
was the whole
confusion/absortption/improvement of philosoophies into 'structured programming' - 
which some will argue is the
same and others maintain a difference (I... - who cares!?). The real 'excitement' was 
stirred up by a paper
(which became very famous) called 'GOTO statement considered harmful' and a massive 
debate erupted as to whether
one could write programs without using GOTOs - is there a GOTO command in PHP? The 
guru at the time was
"Jackson", and if you plug "Jackson structured programming" into Google (or your 
favorite SE) you will be
inundated with 'stuff'.

He wrote a fairly thin and most readable book on the subject, but I doubt it is still 
in print (check Amazon
etc). In those days it was also known as JSP. Unfortunately that acronym has been also 
taken for something else
more recently. The design process, and if you want them, the pretty diagrams, have 
been refined and 'improved'
over the years, so there's plenty of material about. Most likely it is built into 
every 'introduction to
programming' text (that is, programming as a process, not learning a specific 
language!)

These days of course, much of the philosophy of splitting up a monolithic program into 
a series of smaller,
inter-communicating modules has been absorbed into the object-oriented approach (and 
various other 'bits'
grafted on to make it bigger, brighter, and better - as they have become implemented 
(and made practical to use)
in various programming languages/systems). Unfortunately PHP is designed to output 
HTML and that is a very
procedural process, so PHP has limited OO facilities. Reading up about classes and 
encapsulation will pretty
much take you through modular/structured design theory and if you use other 'modern' 
(programming) languages
then that might be a good move for you (us 'old dogs' can handle the concepts, but 
seem to have fundamental
difficulties with the mechanics of the 'new tricks').

Which brings us back to Steven's third point - that such things can be overdone. 
Structure (of whichever flavor)
is designed to make the coding/debugging/come back and extend/'improve' it later, 
processes of development more
efficient. This is quite separate from execution efficiency. However there is no way 
one can improve one, and
neglect the other - nor should vice-versa be allowed to become an excuse for slapdash 
coding practices!

Some people associate the word 'module' with (in PHP) 'function'. So they think of 
modular programming as a code
that is divided up into a series of subroutines, ie functions/calls. This is overly 
simplistic. Each WHILE loop
(for example) is also a 'module'. It has a particular purpose, contains a set/module 
of functionality, and has
definable beginning and end-points/conditions.

Deciding how to best structure your code to suit the process is a question that 
appears here quite often - how
often are we asked something like: 'I have a database listing a series of ... and I 
want to copy these out to an
HTML table with n-columns across the screen' and the neophyte coder is quite confused 
and wants to know how to
handle the (exceptions of) situation? The problem is one of 'structure': the database 
yields a one-dimensional
list of 'whatevers', but the output screen is a table divided into n-columns - and 
worse, the complication is
(handling the exception conditions, for example) that we don't know if the number of 
db-rows divides evenly
between the number of screen-columns. So most start coding and take their 'structure' 
from the database call, ie
a list, and then try to 'share out' the rows across the screen - and get into trouble 
when it doesn't all fit
together neatly (without 'exceptions').

Structured programming suggests that one examines (diagramming) the structure of the 
input and compare that with
the structure of the output format. These two structures should then be 'aligned'. In 
doing this it comes down
to a choice: do I take the list and split it up into m number of table rows, 
n-pieces/columns at a time (and
handle non-uniformity at the end); or do I output all the HTML for a column, within a 
row, within a table - and
when I need it, call for the next db-row data from the source db (if there is any).

So when you look at 'structured programming' you can see that it has more to do with 
'data' than with code - at
first. When you get to the code, you will see that the structure of the code looks 
somewhat like the structure
of the data - and that the way to process splits up quite 'naturally' into 'modules', 
ie HTML table processing
begins on line X1 and proceeds to line Y1, within that row processing is between lines 
X2 and Y2, and within
that item/column processing fits between X3 and Y3 - and finding the input data from 
the database is handled in
a procedure off to this side, which in turn grabs data from a resultset that was 
retrieved from the DB by
function ABC...

Reading other people's code is a good idea to learn about techniques and the 
programming language. However, as a
means of absorbing style and design decisions the maxim most often heard is 'do as I 
say, not as I do'! So I
recommend a bit of background reading and then 'finding your own way/style' as you 
gather experience/fit in with
corporate requirements.

Regards,
=dn


--- End Message ---
--- Begin Message ---
Hey,
The entire concept of OOP was based on the data and not the processing :)

But, no one has yet addressed the core of my question. How can I make any
application plugable? I am trying to create a standard which will work with
every other language. A simple example of what I am attempting to do is :
I have a guestbook A. I have features in it
a. allow public viewing of records
b. dont allow publiv viewing of records

Now, this is very simply, I could just store the on/off value and then
validate agianst that. But when it comes to bigger applications, and more
complex situations, where you have to make choices like, allowing the data
to be written to a dbase or no, wether it should get processed or no. How
does one handle such situations?

Regards,
Kunal Jhunjhunwala

"Minds think with ideas, not information. No amount of data, bandwidth, or
processing power can substitute for inspired thought." - Clifford Stoll
----- Original Message -----
From: "DL Neil" <[EMAIL PROTECTED]>
To: "Kunal Jhunjhunwala" <[EMAIL PROTECTED]>; "Steven Walker"
<[EMAIL PROTECTED]>
Cc: "php-list" <[EMAIL PROTECTED]>
Sent: Saturday, February 16, 2002 4:10 PM
Subject: Re: [PHP] modular programming


> Dear Steven and Kunal,
> Agreed with what you had to say.
>
> > In my experience, 'modular coding' is entirely a process of evolution.
> > It's impossible to sit down and design software on paper. Every piece of
> > code I write is under constant evaluation. Each time a weakness is
> > exposed, I rethink my strategy. Often there is no 'perfect' solution,
> > since each presents a different set of compromises. Devoting yourself to
> > endlessly rewriting and structuring your code will, in the long term,
> > yield better code than anyone can advise in a book or paper.
>
> This para gives an impression that modular programming is an iterative
process (maybe not Steven's intention).
> An iterative approach would certainly enable you to improve the quality of
your code - at some expense to
> rethink/re-implement, and such improvements may well occur through changes
to the modularisation/interfaces
> between modules. Modular programming as a philosophy though, starts at the
program design stage, not at version
> two!
>
> 'Modular programming' as a concept is quite old (in computer/doggie
years). Then there was the whole
> confusion/absortption/improvement of philosoophies into 'structured
programming' - which some will argue is the
> same and others maintain a difference (I... - who cares!?). The real
'excitement' was stirred up by a paper
> (which became very famous) called 'GOTO statement considered harmful' and
a massive debate erupted as to whether
> one could write programs without using GOTOs - is there a GOTO command in
PHP? The guru at the time was
> "Jackson", and if you plug "Jackson structured programming" into Google
(or your favorite SE) you will be
> inundated with 'stuff'.
>
> He wrote a fairly thin and most readable book on the subject, but I doubt
it is still in print (check Amazon
> etc). In those days it was also known as JSP. Unfortunately that acronym
has been also taken for something else
> more recently. The design process, and if you want them, the pretty
diagrams, have been refined and 'improved'
> over the years, so there's plenty of material about. Most likely it is
built into every 'introduction to
> programming' text (that is, programming as a process, not learning a
specific language!)
>
> These days of course, much of the philosophy of splitting up a monolithic
program into a series of smaller,
> inter-communicating modules has been absorbed into the object-oriented
approach (and various other 'bits'
> grafted on to make it bigger, brighter, and better - as they have become
implemented (and made practical to use)
> in various programming languages/systems). Unfortunately PHP is designed
to output HTML and that is a very
> procedural process, so PHP has limited OO facilities. Reading up about
classes and encapsulation will pretty
> much take you through modular/structured design theory and if you use
other 'modern' (programming) languages
> then that might be a good move for you (us 'old dogs' can handle the
concepts, but seem to have fundamental
> difficulties with the mechanics of the 'new tricks').
>
> Which brings us back to Steven's third point - that such things can be
overdone. Structure (of whichever flavor)
> is designed to make the coding/debugging/come back and extend/'improve' it
later, processes of development more
> efficient. This is quite separate from execution efficiency. However there
is no way one can improve one, and
> neglect the other - nor should vice-versa be allowed to become an excuse
for slapdash coding practices!
>
> Some people associate the word 'module' with (in PHP) 'function'. So they
think of modular programming as a code
> that is divided up into a series of subroutines, ie functions/calls. This
is overly simplistic. Each WHILE loop
> (for example) is also a 'module'. It has a particular purpose, contains a
set/module of functionality, and has
> definable beginning and end-points/conditions.
>
> Deciding how to best structure your code to suit the process is a question
that appears here quite often - how
> often are we asked something like: 'I have a database listing a series of
... and I want to copy these out to an
> HTML table with n-columns across the screen' and the neophyte coder is
quite confused and wants to know how to
> handle the (exceptions of) situation? The problem is one of 'structure':
the database yields a one-dimensional
> list of 'whatevers', but the output screen is a table divided into
n-columns - and worse, the complication is
> (handling the exception conditions, for example) that we don't know if the
number of db-rows divides evenly
> between the number of screen-columns. So most start coding and take their
'structure' from the database call, ie
> a list, and then try to 'share out' the rows across the screen - and get
into trouble when it doesn't all fit
> together neatly (without 'exceptions').
>
> Structured programming suggests that one examines (diagramming) the
structure of the input and compare that with
> the structure of the output format. These two structures should then be
'aligned'. In doing this it comes down
> to a choice: do I take the list and split it up into m number of table
rows, n-pieces/columns at a time (and
> handle non-uniformity at the end); or do I output all the HTML for a
column, within a row, within a table - and
> when I need it, call for the next db-row data from the source db (if there
is any).
>
> So when you look at 'structured programming' you can see that it has more
to do with 'data' than with code - at
> first. When you get to the code, you will see that the structure of the
code looks somewhat like the structure
> of the data - and that the way to process splits up quite 'naturally' into
'modules', ie HTML table processing
> begins on line X1 and proceeds to line Y1, within that row processing is
between lines X2 and Y2, and within
> that item/column processing fits between X3 and Y3 - and finding the input
data from the database is handled in
> a procedure off to this side, which in turn grabs data from a resultset
that was retrieved from the DB by
> function ABC...
>
> Reading other people's code is a good idea to learn about techniques and
the programming language. However, as a
> means of absorbing style and design decisions the maxim most often heard
is 'do as I say, not as I do'! So I
> recommend a bit of background reading and then 'finding your own
way/style' as you gather experience/fit in with
> corporate requirements.
>
> Regards,
> =dn
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--- End Message ---
--- Begin Message ---
Hey Kunal,

> The entire concept of OOP was based on the data and not the processing :)

No, this seems too much of a simplification. In the 'good old days' we used to design 
a program by using a
flowchart. Such is an entirely procedural/code-based approach. Each of the 
philosophies that followed/developed
from there, suggested that we should pay (more) attention to the data (and its 
structure/characteristics).
However none is exclusively "based on the data and not the processing". You need to 
consider both and not one at
the expense of the other... This point was emphasised by an earlier correspondent!

> But, no one has yet addressed the core of my question.

What do you mean? Here is the original question:
-----
does anyone know of any good papers on modular programing? I have been able
to make my code modular, but I am not satisfied with it. I am trying to make
my program work the "plug in" way.. where i can just add more modules on the
fly... any tips? :)
-----
Which bits were addressable by someone else, and which parts are very much restricted 
by knowledge only in your
head? The "add more modules on the fly" was such a mixture of terminology/buzz-words 
as to sound
Superman-futuristic!? (include files possibly?)

Two suggestions:
- do the reading and sort out your approach, then roll forward into the specific 
application/review its
design/modularity etc
- address a specific situation (as below) by describing your objectives for it, the 
necessary parameters, what
you have done so far, etc
Don't muddle the entire process of LEARNING about a philosophy/approach, with 'fixing' 
a specific piece of code.

How can I make any
> application plugable? I am trying to create a standard which will work with
> every other language. A simple example of what I am attempting to do is :
> I have a guestbook A. I have features in it
> a. allow public viewing of records
> b. dont allow publiv viewing of records
>
> Now, this is very simply, I could just store the on/off value and then
> validate agianst that. But when it comes to bigger applications, and more
> complex situations, where you have to make choices like, allowing the data
> to be written to a dbase or no, wether it should get processed or no. How
> does one handle such situations?

What's wrong with your 'guestbook' solution? If you're not satisfied, start a new 
conversational thread (ie with
a more descriptive title) because there are many experienced 'guest bookers' on the 
list, who will be more than
capable/happy to share ideas/experience.

The philosophies behind modular programming, structured programming, and 
object-oriented programming all unite
in the realisation that "bigger applications" and "more complex situations" can be 
rendered to be collections of
smaller and less complex 'units' that can be individually programmed (and tested) as 
'simple solutions', and
then combined together to provide size, complexity, and power. (and so we're back to 
doing a bit of reading up
on/absorbing the subject!)

Regards,
=dn


--- End Message ---
--- Begin Message ---
At 02:33 PM 2/15/2002 +0100, marcbey wrote:
>i dont know how i have to send it back, because i dont kown where and how to
>put the
>ASPSESSIONIDKJHKJHHKJH=HJVHJGHJGJGHJGJHGKJ information (in the header?)

This document may help:

http://developer.netscape.com:80/docs/manuals/js/client/jsref/cookies.htm

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

_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com
--- End Message ---
--- Begin Message ---
Hi All,

I am running Apache with PHP4 as a module.  I have also written a script 
(template.php) that sets up the default envrionment, like the CSS and navigation etc.  
The script also reads in a file, as defined by the ?path= of the URL.  The file it 
reads in must have the sections (includes, header and body,  as defined by /*** ***/ 
and /*** end ***/ pairs).  The file is the split into these sections and along with 
the templated bits of the page compile into a single string which is the executed 
using the eval().  Now this all works fine, but I also want to use sessions.  The 
first session from the index.html file, which is first acessed as a login page, stores 
the player class fine, but when I go to the next page (player_login.html) I seem to 
loose the session.

You might ask why I don't just use an existing templating system, well it's because I 
think that you should only have to write the template once and not have to touch it 
again.  The templating systems I have come across force you to include a file at the 
top and bottom of the code you are writing.  The one down side to the way I am doing 
it is that I have had to force the other file into a include, header and body section, 
but this is a trivial formatting issue.

Is there something I'm missing?  I have included the code for the three scripts below.

--------
template.php
--------

<?PHP
/*
 * This script is the basis for a templaing engine.  The engine uses the
 * rewrite feature of the web server to capture the Virtual URL that the
 * user wants and maps it to this script with a paraeter.  This script
 * then sets up the template and includes the content from the file
 * indicated by the user.
 *
 * A directory structure containing tall of the content is required, and
 * with Apache a directory to map from.
 */


/* Put setup here */
require_once("site-config.php");
require_once("html_header.php");
require_once("html_footer.php");
require_once("misc_function.php");


/* Set up some defaults */
$title = "";
$body = "";
$page = "";
$file_read = false;
$file_content = "";
unset($content_header);

/* Read the contents of a file into a string */
function read_file($filename)
{
        global $file_read;
        global $file_content;
        $file_content = "";
        $file_read = false;
        //print "$filename\n\n<br><br>";
        if(file_exists($filename))
        {
                $page_code = file($filename);
                foreach ($page_code as $line)
                {
                        $file_content .= $line;
                }
                //print "$file_content";
                $file_read = true;
        }
        else
        {
                $file_content = '
                        <h1>File Not Found</h1>
                        <p>Could not find <?=$filename?>, please let the Web 
Administrator
                        know</p>
                        ';
        }
}

/* Get the index information */

read_file($NAV_COLUMN);
$navigation = $file_content;

/* 
 * garentee that if the user gives no file name then they will get the
 * index file
 */
if(strcmp(basename($path), "") == 0)
{
        if(!preg_match("/\/$/", $path))
        {
                $path .= "/";
        }
        $path .= "index.html";
}
/* Get the Header information and the content of the body */
$file_name = "$CONTENT_PATH/$path";
read_file($file_name);
if($file_read)
{
        //print "$file_name";

        /* Grab the HTTP header stuff from the file. This includes any
         * session information.
         *
         * The header section is defined by 
         * <*** header ***> and <*** end header ***> at the start of the
         * file.
         */
        $section = preg_split("/\s*<\*{3}\s*end\s*header\s*\*{3}>\s*/im",
                        $file_content,
                        2
                        );
        if(count($section) == 2)
        {
                $content_header = $section[0];
                $content_header = preg_replace("/<\*{3}\s*header\s*\*{3}>/im",
                                "",
                                $content_header,
                                1
                                );
                $body = $section[1];

                /* get the includes section */
                $section = preg_split("/\s*<\*{3}\s*end\s*includes\s*\*{3}>\s*/im",
                        $content_header,
                                2
                                );
                if(count($section) == 2)
                {
                        $include_files = $section[0];
                        $include_files = preg_replace("/<\*{3}\s*includes\s*\*{3}>/im",
                                        "",
                                        $include_files,
                                        1
                                        );
                        $content_header = $section[1];

                }

        }
        else
        {
                $body = $section[0];
        }
}
else
{
        $body = $file_content;
}

if(isset($include_files))
{
        $page .= $include_files."\n";
}

$page .= '<?PHP
/*
 * Start of Template code 
 */

/* include state management here in an if to see if it is wanted */

if(defined($KEEP_STATE) && $KEEP_STATE)
{
        session_start();
} 
/* Set up the headers and footers */
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

/* keep state = '.$KEEP_STATE.' */

?>
';

if(isset($content_header))
{
        $page .= $content_header."\n";
}


$page .= '
<?PHP
/* 
 * Start of Template code section 
 */
$header = new html_header($title);
$footer = new html_footer();
$header->display()
?>'."\n";
//$header->display();
//print "<h1>:$title</h1>";

/*
print "<br><stong>header</strong>";
highlight_string($content_header);
*/

$page .= '<table summary="naigation" width="100%" height="100%">'."\n";
$page .= '<tr>'."\n";
$page .= '  <td width="83" class="index">'."\n";
$page .= $navigation;
//$page .= "<span class=\"index\">fred&nbsp;</span>\n";
$page .= '  </td>'."\n";
$page .= '  <td>'."\n";

/*
$page .= "<br><strong>body<strong><BR>";
highlight_string($body);
*/

$page .= $body."\n";

$page .= '<?$test = session_id();print "session_id = $test";?>';
$page .= '<?print "phpid = $PHPSESSID";?>';

$page .= '  </td>'."\n";
$page .= '</tr>'."\n";
$page .= '</table>'."\n";

$page .= '<?$footer->display();?>'."\n";

print eval("?>".$page);
if($DEBUG)
{
        ?><h1>Debuging Information Follows</h1>
        <table width="100%"><TR><TD width="83">&nbsp;</TD><TD>
        <?
                //print "<h2>Base Name = ".basename($path)."</h2>";
                /* 
                 * This section adds line numbers to the string so you can make
                 * sense out of the eval line numbers when an error is produced.
                 *
                 * IT WOULD BE A VERY GOOD IDEA TO TURN THIS INTO A FUCTION FOR
                 * FUTURE USE.
                 */
                flush();
                ob_start();
                
                highlight_string($page);

                $page = ob_get_contents();

                ob_end_clean();

                $new_page = preg_split('/<br\s*\/>/s', $page, -1);
                $i = 0;
                $page = "";
                while($i < count($new_page))
                {
                        $line_no = $i + 1;
                        $page .= "<font color=\"black\">$line_no: </font> 
".$new_page[$i]."<br \/>";
                        $i++;
                }
                /* End line number section */
                print $page;
        ?>
        </TD></tr></table>
<?
}

?>

--------
index.html
--------
<*** includes ***>
<?PHP
/*
 * Put any include or require statments here
 */
require_once("modules/login_box.php");
require_once("database.php");
require_once("player.php");
require_once("modules/new_user.php");


?>
<*** end includes ***>
<*** header ***>
<?PHP
/* Put any session information here and other code which must be run
 * before the HTML is actually sent.
 */
global $db;
global $player;
global $nick_name;
$login_failed = TRUE;

$login_box = new login_box($LOGIN_ACTION);
$title = "";

if(isset($nick_name))
{
        /* The user has attempted to login */

        if(isset($new_user) && $new_user)
        {
                $title = "New User Registration";
        }
        else
        {
                if(isset($register) && $register)
                {
                        /* The user is submitting their details */

                        // Check if the user id already exists.
                        $query = "SELECT id FROM player WHERE nickname = '$nick_name'";

                        $result = $db->query($query);

                        if(DB::isError($result))
                        {
                                die("Checking id: ".$result->getMessage());
                        }

                        if($result->numRows() > 0)
                        {
                                error_message("This nick name/login already exists, 
please try another");
                        }

                        // Add the user.
                        if(isset($nick_name) && (strlen($nick_name) > 0)
                                && !preg_match("/^\s*$/", $nick_name))
                        {
                                $column = "nickname";
                                $values = "'".trim($nick_name)."'";
                        }
                        if(isset($password) && (strlen($password) > 0)
                                && !preg_match("/^\s*$/", $password))
                        {
                                $password = md5(trim($password));
                                $password2 = md5(trim($password2));
                                if(strcmp($password, $password2) == 0)
                                {
                                        $column .= ", password";
                                        $values .= ", '".$password."'";
                                }
                                else
                                {
                                        error_message("Your passwords don't match 
please"
                                        . " entre them again :$password:$password2:");
                                }

                        }
                        if(isset($first_name) && (strlen($first_name) > 0)
                                && !preg_match("/^\s*$/", $first_name))
                        {
                                $column .= ", firstname";
                                $values .= ", '".trim($first_name)."'";
                        }
                        if(isset($last_name) && (strlen($last_name) > 0)
                                && !preg_match("/^\s*$/", $last_name))
                        {
                                $column .= ", lastname";
                                $values .= ", '". trim($last_name)."'";
                        }
                        if(isset($email) && (strlen($email) > 0)
                                && preg_match("/^[^@]+@[^.]+\..*$/", $eamil))
                        {
                                $column .= ", email";
                                $values .= ", '".trim($email)."'";
                        }
                        if(isset($street) && (strlen($street) > 0)
                                && !preg_match("/^\s*$/", $street))
                        {
                                $column .= ", street";
                                $values .= ", '".trim($street)."'";
                        }
                        if(isset($suburb) && (strlen($suburb) > 0)
                                && !preg_match("/^\s*$/", $suburb))
                        {
                                $column .= ", suburb";
                                $values .= ", '".trim($suburb)."'";
                        }
                        if(isset($state) && (strlen($state) > 0)
                                && !preg_match("/^\s*$/", $state))
                        {
                                $column .= ", state";
                                $values .= ", '".trim($state)."'";
                        }
                        if(isset($postcode) && (strlen($postcode) > 0)
                                && !preg_match("/^\s*$/", $postcode))
                        {
                                $column .= ", postcode";
                                $values .= ", ".trim($postcode);
                        }
                        $column .= ", preferedname";
                        if(isset($prefered_name))
                        {
                                if(strcmp($prefered_name, "nick_name") == 0)
                                {
                                        $values .= ", true";
                                }
                                else
                                {
                                        $values .= ", false";
                                }
                        }
                        else
                        {
                                $values .= ", false";
                        }
                        if(isset($list))
                        {
                                if(strcmp($list, "true"))
                                {
                                        // Send an email to the list
                                }
                        }

                        //Get a valid Id
                        // This needs work so it won't break if we get more than 
max(int2)
                        // users
                        $query = "SELECT id FROM player ORDER BY id DESC";
                        $result = $db->query($query);
                        if(DB::isError($result))
                        {
                                die("Getting valid id:  ".$result->getMessage());
                        }
                        $row = $result->fetchRow();
                        $id = $row[0] + 1;
                        $column .= ", id";
                        $values .= ", $id";

                        // Set the user active
                        $column .= ", active";
                        $values .= ", true";

                        $query = "INSERT INTO player ($column) VALUES ($values)";
                        //print $query;

                        $result = $db->query($query);

                        if(DB::isError($result))
                        {
                                print "$query<br>";
                                die("Inserting new player:  ".$result->getMessage());
                        }

                }
                else
                {
                        /* 
                         * We only need to calculate the password if the user is
                         * an existing user 
                         */
                        $password = md5(trim($password));
                }

                // Check the database for this user
                //session_register_var("nick_name", $nick_name);
                session_register("nick_name");
                $GLOBALS["nick_name"] = $nick_name;
                $title = $nick_name;

                $query = "SELECT id "
                        ."FROM player "
                        ."WHERE nickname = '".trim($nick_name)."' "
                        ."  and password = '$password'";

                $result = $db->query($query);

                if(DB::isError($result))
                {
                        die("Geting registered user:  ".$result->getMessage());
                }

                if($result->numRows() != 0)
                {
                        $row = $result->fetchRow();
                        //      print "<br>$password<br>$row[0]<br>";

                        $player = new player($row[0], $db);
                        session_register_var("player", $player);

                        // Yeah!  The user loged in sussessfully and we can give them 
their
                        // useable page.
                        $login_failed = FALSE;

                }

                if($login_failed)
                {
                        $title = "Login Failed";
                }
                else
                {
                        $title = "Welcome";
                }
        }

}
else
{
        /* The user has not attempted to login */
        $title = "Login";
}



?>
<*** end header ***>
<?PHP
/* This section is where your HTML code goes and any code which can run
 * in the HTML
 */

if(isset($nick_name))
{
        /* The user has attempted to login */
        if(isset($new_user) && $new_user)
        {
                if(isset($password))
                {
                        new_user_form($nick_name, $password);
                }
                else
                {
                        new_user_form($nick_name);
                }
        }
        else
        {
                if($login_failed)
                {
                        ?>
                                <p>Please try loging in again.  You may have mispelled 
your
                                nick name or password</p>
                                <?PHP
                                $login_box->display($nick_name);
                }
                else
                {
                        ?>
                                <p>Welcome to Maric's Place</p>
                                <?PHP
                                session_register_var("player", $player);
                }
        }

}
else
{
/* The user has not attempted to login */
        $login_box->display();
}

?>

------
player_list.html
------
<*** includes ***>
<?PHP
/* Put any session information here and other code which must be run
 * before the HTML is actually sent.
 */
 require_once('database.php');
 require_once('player.php');
?>
<*** end includes ***>

<*** header ***>
<?PHP

 global $db;
 global $player;
 $title = "Player List";
 $i;

?>
<*** end header ***>
<?PHP
/* This section is where your HTML code goes and any code which can run
 * in the HTML
 */

$query = "SELECT firstname, lastname, nickname FROM player";
$result = $db->query($query);
if(DB::isError($result))
{
        die("Couldn't list Players: ".$result->getMessage());
}

?>
<table summary="Player List" border="1" align="center" cellpadding="2">
<tr>
        <td><strong>First Name</strong></td>
        <td><strong>Last Name</strong></td>
        <td><strong>Alias</strong></td>
</tr>
<?PHP
//print $player->first_name();
$i = 0;
while($i < $result->numRows())
{
        $row = $result->fetchRow();
        print "<tr>\n";
        foreach ($row as $cell)
        {
                print "<td>".htmlentities($cell) ."</td>\n";
        }
        print "</tr>\n";
        $i++;
}
?>
</table>
<?PHP
print $player.":<br>\n";
print $nick_name."+<br>\n";
print session_id()."-<br>\n";
?>

-- 
Justin 'Doychi' Deutsch
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
I'm attempting to do some dynamic XML output to an xml capable browser.  Can
someone give me an example?  I'm using .php files currently. Tried xml files
and the tags were messing up my xml output or if I used <?php this would
show up as an xml object.

Running Redhat Linux 7.2 with apache on the server side.  Any help would be
GREATLY appreciated.


Thanks!


--- End Message ---
--- Begin Message ---
Hello,

    I have read on php.net that the vpopmail functions are available in 4.0.5 and 
later.  However, I have not been able to successfully use then on 4.0.6 or 4.1.0.  Is 
this something that needs to be enabled, or am I doing something incorrectly?


Pete~
--- End Message ---
--- Begin Message ---
On Saturday 16 February 2002 16:47, Pete Bekisz wrote:
> Hello,
>
>     I have read on php.net that the vpopmail functions are available in
> 4.0.5 and later.  However, I have not been able to successfully use then on
> 4.0.6 or 4.1.0.  Is this something that needs to be enabled, or am I doing
> something incorrectly?


PHP needs to be compiled with the vpopmail option.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
The less a statesman amounts to, the more he loves the flag.
                -- Kin Hubbard
*/
--- End Message ---
--- Begin Message ---
I want to run a query like:

select * from table order by rand() limit 3

in MySQL it would work but I need to run it in MSSQL.  I've been searching for a limit 
function in MSSQL and I can't find a way to do it.  I'm experienced with MySQL but 
know nothing about MSSQL.  If someone could point me in the right direction I would 
really appreciate it!

Thanks,
Dean

--- End Message ---
--- Begin Message ---
On Saturday 16 February 2002 17:14, Dean Householder wrote:
> I want to run a query like:
>
> select * from table order by rand() limit 3
>
> in MySQL it would work but I need to run it in MSSQL.  I've been searching
> for a limit function in MSSQL and I can't find a way to do it.  I'm
> experienced with MySQL but know nothing about MSSQL.  If someone could
> point me in the right direction I would really appreciate it!

I think it's TOP in MSSQL.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Let's remind ourselves that last year's fresh idea is today's cliche.
                -- Austen Briggs
*/
--- End Message ---
--- Begin Message ---
Is anyone familiar with how exactly to use the TOP command in MSSQL?  Is it
in it's own SQL query or built into the select query?  I'm looking at the
help and it doesn't seem very helpful...

Dean


----- Original Message -----
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 16, 2002 2:28 AM
Subject: Re: [PHP] Is there an MSSQL limit function?


> On Saturday 16 February 2002 17:14, Dean Householder wrote:
> > I want to run a query like:
> >
> > select * from table order by rand() limit 3
> >
> > in MySQL it would work but I need to run it in MSSQL.  I've been
searching
> > for a limit function in MSSQL and I can't find a way to do it.  I'm
> > experienced with MySQL but know nothing about MSSQL.  If someone could
> > point me in the right direction I would really appreciate it!
>
> I think it's TOP in MSSQL.
>
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>
> /*
> Let's remind ourselves that last year's fresh idea is today's cliche.
> -- Austen Briggs
> */
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Saturday 16 February 2002 17:48, Dean Householder wrote:
> Is anyone familiar with how exactly to use the TOP command in MSSQL?  Is it
> in it's own SQL query or built into the select query?  I'm looking at the
> help and it doesn't seem very helpful...

It's been a while since I last used MS dbs. But I think it goes something 
like:


SELECT * FROM table TOP 5;


In fact I checked the help of Access and it is detailed there.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
The primary requisite for any new tax law is for it to exempt enough
voters to win the next election.
*/
--- End Message ---
--- Begin Message ---
I figured it out!

For benefit of all I'm posting the answer:

select top 3 * from table

This query will return the top three rows of the table but now I want to
them to be random.

Once again, in MySQL you could just say "order by rand()" but that doesn't
work in MSSQL.  Does anyone know how to do this?

Dean

----- Original Message -----
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 16, 2002 2:54 AM
Subject: Re: [PHP] Is there an MSSQL limit function?


> On Saturday 16 February 2002 17:48, Dean Householder wrote:
> > Is anyone familiar with how exactly to use the TOP command in MSSQL?  Is
it
> > in it's own SQL query or built into the select query?  I'm looking at
the
> > help and it doesn't seem very helpful...
>
> It's been a while since I last used MS dbs. But I think it goes something
> like:
>
>
> SELECT * FROM table TOP 5;
>
>
> In fact I checked the help of Access and it is detailed there.
>
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>
> /*
> The primary requisite for any new tax law is for it to exempt enough
> voters to win the next election.
> */
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
At 05:54 PM 2/16/2002 +0800, Jason Wong wrote:
>On Saturday 16 February 2002 17:48, Dean Householder wrote:
> > Is anyone familiar with how exactly to use the TOP command in MSSQL?  Is it
> > in it's own SQL query or built into the select query?  I'm looking at the
> > help and it doesn't seem very helpful...
>
>It's been a while since I last used MS dbs. But I think it goes something
>like:
>
>
>SELECT * FROM table TOP 5;

Actually it's

SELECT TOP 5 * FROM table;

I've had some recent experience attempting to find an equivalent to the 
LIMIT clause in MSSQL.  No one method is really ideal, but here are a 
couple of ways:

1. Use subselects

One method is to use a mixture of the TOP clause along with subselects to 
get a certain record range out.  Let's say that you have a result set and 
you want to get rows 30-39 (assuming the first row is zero).  This is one way:

select * from
(select top 10 * from
(select top 40 * from ... where ... order by ... desc)
as ax order by ...)
as aa order by ... desc

This is pretty odd, but basically what it does is select the top 40 records 
in reverse order, then from that result set it selects the top 10 (getting 
records 39-30).  The outermost select statement reverses the order again so 
you get records 30-39.

The problem with this method is that it gets slower the higher up in the 
result set you go.  It always has to select as least as many rows as the 
highest row number you want to get.  If your full result set contains 1000 
rows, and you need rows 550-560, your statement still has to select at 
least 560 rows to work.

2. Used a temp table inside a stored procedure

This is probably the better solution.  Basically what you do is create a 
stored procedure that selects all of your results into a temp table with an 
row counter column (field type IDENTITY), and then select the results out 
of the temp table where (Row >= @Start) AND (Row <= @End).  There is a nice 
article that explains this method in detail here:

http://www.15seconds.com/Issue/010308.htm

This isn't really related to paging, just more of a general tip:  I have 
found Sybase's Transact-SQL User's Guide on their website to be very 
helpful in working with MSSQL.  For the most part the syntax is exactly the 
same, and the site is easy to navigate IMHO.  Call me crazy, but I've found 
it generally more helpful than the Books On-Line. YMMV:

http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookView

--- End Message ---
--- Begin Message ---
Hi,

After the help given on my last script I got a bit more advanced. I am
trying to write a user auth script and start sessions. I wrote this script
and ran it and I am getting an error on line 4. Once again I cannot see any
problems. I would appriciate you experienced guys casting your eyes over it
and pulling up any errors you see in the functionality.

Thanks,


Matt.




script attatched in file user_auth.txt
<?php 

include("../dbconnect.php");
include("../functions/common_functions.php"):


session_start();


if (!isset($login_username)) {
?>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="vi">
<META NAME="Author" Content="Matthew Darcy">

<TITLE>BathJobs.com User Login</TITLE>

</HEAD>
<BODY BGCOLOR=#ffffff LINK=#000000 ALINK=#000000 VLINK=#000000>
<FONT FACE=Arial Size=4 Color=black>
<P>
<FORM METHOD="post" ACTION="<?=$PHP_SELF?>">
<BR><CENTER>
BathJobs.com Login <BR><BR>

<TABLE BGCOLOR=#ffffff BORDER=0 > 
<TR BGCOLOR=#191970>
        <TD BGCOLOR=#191970 width=30 height=30 > <B><FONT 
color=#ff9900>UserName</FONT>  </B> </TD>
        <TD BGCOLOR=#191970 width=30 height=30 ><INPUT NAME="login_username" SIZE=8 
     ></TD>
</TR>
<TR>
        <TD BGCOLOR=#191970 width=30 height=30 > <B><FONT color=#ff9900>Password 
</FONT>  </B> </TD>
        <TD BGCOLOR=#191970 width=30 height=30 ><INPUT NAME="login_password" SIZE=8 
     ></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="hidden" NAME="user_login_submit_button" VALUE="submit_login" >
<INPUT TYPE="submit" NAME="submit_login_details" VALUE="Login">
<BR>
</FORM>


<P>&nbsp;</P></CENTER></FORM></FONT>

</BODY>
</HTML>
<?php
exit;
}


session_register("login_username");
session_register("login_password");


$sql_authorisation = "SELECT * FROM account_details WHERE 
account_name='$login_username' AND account_password=PASSWORD('$login_password');
$sql_authorisation_result = mysql_query($sql_authorisation);

if (!$result) { 
        error("A Database Error Occurred while trying to authorise login details" 
        "\\nIf this problem persists, please contact [EMAIL PROTECTED]");
}




if (mysql_num_rows($sql_authorisation_result) == 0) {
        session_unregister("login_username");
        session_unregister("login_password");
?>

<HTML>
<HEAD>
<TITLE> Access Denied </TITLE>
</HEAD>
<BODY BGCOLOR=white>
<H1> Access Denied </H1>
<P> Your user ID and Password could not be verified. This could be an incorrect 
username or password, or you are not a registered user on this site. Try logging in 
again checking your details, or enter the signup process to join bathjobs.com</P>
</BODY>
</HTML>
<?php

exit;
}

?>
--- End Message ---
--- Begin Message ---
Found 1 schoold box error AGAIN I ended line 4 with : not ;

I am now getting the parse error on line 64

Can anyone review this script and tell me where I am going wrong.

Thanks,

Matt.


--------------------------------SCRIPT
START----------------------------------

<?php

include("../dbconnect.php");
include("../functions/common_functions.php");


session_start();


if (!isset($login_username)) {
?>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="vi">
<META NAME="Author" Content="Matthew Darcy">

<TITLE>BathJobs.com User Login</TITLE>

</HEAD>
<BODY BGCOLOR=#ffffff LINK=#000000 ALINK=#000000 VLINK=#000000>
<FONT FACE=Arial Size=4 Color=black>
<P>
<FORM METHOD="post" ACTION="<?=$PHP_SELF?>">
<BR><CENTER>
BathJobs.com Login <BR><BR>

<TABLE BGCOLOR=#ffffff BORDER=0 >
<TR BGCOLOR=#191970>
        <TD BGCOLOR=#191970 width=30 height=30 > <B><FONT
color=#ff9900>UserName</FONT>  </B> </TD>
        <TD BGCOLOR=#191970 width=30 height=30 ><INPUT NAME="login_username" SIZE=8
     ></TD>
</TR>
<TR>
        <TD BGCOLOR=#191970 width=30 height=30 > <B><FONT color=#ff9900>Password
</FONT>  </B> </TD>
        <TD BGCOLOR=#191970 width=30 height=30 ><INPUT NAME="login_password" SIZE=8
     ></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="hidden" NAME="user_login_submit_button" VALUE="submit_login" >
<INPUT TYPE="submit" NAME="submit_login_details" VALUE="Login">
<BR>
</FORM>


<P>&nbsp;</P></CENTER></FORM></FONT>

</BODY>
</HTML>
<?php
exit;
}


session_register("login_username");
session_register("login_password");


$sql_authorisation = "SELECT * FROM account_details WHERE
account_name='$login_username' AND
account_password=PASSWORD('$login_password');
$sql_authorisation_result = mysql_query($sql_authorisation);

if (!$sql_authorisation_result) {
        error("A Database Error Occurred while trying to authorise login details"
        "\\nIf this problem persists, please contact [EMAIL PROTECTED]");
}




if (mysql_num_rows($sql_authorisation_result) == 0) {
        session_unregister("login_username");
        session_unregister("login_password");
?>

<HTML>
<HEAD>
<TITLE> Access Denied </TITLE>
</HEAD>
<BODY BGCOLOR=white>
<H1> Access Denied </H1>
<P> Your user ID and Password could not be verified. This could be an
incorrect username or password, or you are not a registered user on this
site. Try logging in again checking your details, or enter the signup
process to join bathjobs.com</P>
</BODY>
</HTML>
<?php

exit;
}

?>

--- End Message ---
--- Begin Message ---
> I am now getting the parse error on line 64
> $sql_authorisation = "SELECT * FROM account_details WHERE
> account_name='$login_username' AND
> account_password=PASSWORD('$login_password');

You're missing the closing " on the last line above.

--- End Message ---
--- Begin Message ---
never mind Matt,

I noticed the missin ); on line 65

Thanks for your help.

Matt.


-----Original Message-----
From: Matt [mailto:[EMAIL PROTECTED]]
Sent: 16 February 2002 12:05
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP] user auth script update.


> I am now getting the parse error on line 64
> $sql_authorisation = "SELECT * FROM account_details WHERE
> account_name='$login_username' AND
> account_password=PASSWORD('$login_password');

You're missing the closing " on the last line above.

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


I have apache compiled and working %100.

I have www.mydomain.com

when I visit thie domain apache loads index.html for my by default - wo my
browser displays www.mydomain.com - but the page viewed is
www.mydomain.com/index.html

I updated index.html (did not touch any apache configuration) added some
text etc

Now when I visit www.mydomain.com I get page not found however if I visit
www.mydomain.com/index.html I get the updated page. I go to my linux server
and view www.mydomain.com and it works fine ??

Any ideas ?

thanks,

Matt.

--- End Message ---
--- Begin Message ---
got the apache thing sussed.

For some reason windows using ie takes doesn't see changed on the apache
webserver as quick as linux ???



-----Original Message-----
From: Matthew Darcy [mailto:[EMAIL PROTECTED]]
Sent: 16 February 2002 11:58
To: PHP developers
Subject: [PHP] not really a php question but can't hurt to ask.




I have apache compiled and working %100.

I have www.mydomain.com

when I visit thie domain apache loads index.html for my by default - wo my
browser displays www.mydomain.com - but the page viewed is
www.mydomain.com/index.html

I updated index.html (did not touch any apache configuration) added some
text etc

Now when I visit www.mydomain.com I get page not found however if I visit
www.mydomain.com/index.html I get the updated page. I go to my linux server
and view www.mydomain.com and it works fine ??

Any ideas ?

thanks,

Matt.


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

--- End Message ---
--- Begin Message ---
Turn caching off in IE while you're developing ...  or hit refresh so you
get the new page.

----- Original Message -----
From: "Matthew Darcy" <[EMAIL PROTECTED]>

> For some reason windows using ie takes doesn't see changed on the apache
> webserver as quick as linux ???
>


--- End Message ---
--- Begin Message ---
Hi,
is there someone who can give me some tips to rotate a text-box with 
pdf-lib functions? I've tried with pdf_rotate(...), but i've been not able 
to write a thing in other ways than horizontal.
Thanks. 

--- End Message ---
--- Begin Message ---
Hey,
I am trying to zip an entire directory and its contents on the fly. Any tips
or codes snippets for doing something like this? The one at zend doesnt seem
to be working for me :(
Regards,
Kunal Jhunjhunwala

"Minds think with ideas, not information. No amount of data, bandwidth, or
processing power can substitute for inspired thought." - Clifford Stoll

--- End Message ---
--- Begin Message ---
By default, a session (created with session_register) seems to last just 
as long as the user has their browser open.  If a user quits the 
browser, the session is automatically destroyed.

I want a session to last indefinitely (or until my program destroys 
it).  There are some hints about how this could be done with cookies in 
the documentation, but not a clear recipe.  What sequence of PHP 
statements should I use to achieve this?

Thanks for any help,

Nigel

--- End Message ---

Reply via email to