php-general Digest 24 Dec 2006 04:02:48 -0000 Issue 4531

Topics (messages 246171 through 246184):

Re: Clarification: Jump to a record/PHP paging...
        246171 by: tedd
        246172 by: T.J. Mahaffey
        246173 by: Robert Cummings
        246174 by: tedd

Script's length, echo, and execution speed
        246175 by: Jean-Christophe Roux
        246177 by: Satyam
        246178 by: Paul Novitski
        246179 by: Casey Chu
        246180 by: Jürgen Wind
        246181 by: Jon Anderson

Re: New User Sign up Notification
        246176 by: Casey Chu
        246182 by: Casey Chu
        246183 by: Ryan Fielding

[Announce] GeryEngine a PHP5 template engine
        246184 by: Arjen Brouwer

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 9:03 AM -0600 12/23/06, T.J. Mahaffey wrote:
I see now that I did not explain myself adequately.
I think "jump to record" was the wrong way to put it. So, here goes.

I already have excellent paging functionality working well, based on a nice tutorial at PHPFreaks.

My problem is that when a user performs a search, I need to display the page on which their search string is found, but still display ALL records within the paging of the entire database.
I've since discovered the core of what I need to do:

        1. I can find the record I need through a simple query.

2. I can easily determine WHICH page this record is on by counting BACKWARDS from the found record to the FIRST record, totaling the number of records from record 1 to the found record. Then, by performing a bit of division, I can determine which page that record appears on and direct the user to "...page=8" via $_GET.

SO, my question is: how might I have MySQL tell me how many records came BEFORE the found record? (FYI: there is currently no auto-incrementing ID on these records, so that obviously easy solution would be unavailable.)

Thanks in advance for any insight.

--
T.J. Mahaffey
[EMAIL PROTECTED]


tj:

In my opinion, wrong thinking. You ask how many records appear before and after a search string result. That's like asking "What's the difference between an orange?" -- it doesn't make sense.

The user enters a search string. All records are searched and the correct one is found and presented. Now you want the records that were not correct to be arranged in some manner of before and after correctness -- it doesn't make sense.

You could use a FULL TEXT search in order of relevance, much like what search engines do. But those searches come back with correct searches and then sort them in terms of relevance. They don't show the correct record and then all the records that were before and after correctness. Do you see what I mean?

You could put in a field that has a number assigned to it, and show what numbers came before and after the record selected (like sequence of entry, auto-incrementing ID ), but that isn't relevant to the original search criteria.

You need to think about what you specifically want to show the user -- what would make sense, or of use, to them?

hth's

tedd

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

--- End Message ---
--- Begin Message ---
I agree, tedd. And your points about what makes sense are taken.

That being said, the end point of all this is for a search to simply act like a real person turning the pages of a phone book. All I need to do is take the user to a desired point within the records in the database. This is by request of the client I'm working for, not what makes sense. (As you may well know, these two don't always meet. lol)

At this point, it seems to me that in order to achieve my desired result, I need to incorporate an auto-incremented ID column in the table so that this value may be used to calculate the number of records before the found record.(ie, if the found record's ID is 201, then there were 200 records before it. Divide 200 by 100 records per page and the desired result is on page 3.)

Assuming no one else sees a method to achieve the desired result without such a change.
Thank you, tedd, for your input. It does help to have someone

--
T.J. Mahaffey
[EMAIL PROTECTED]




On Dec 23, 2006, at 10:05 AM, tedd wrote:
tj:

In my opinion, wrong thinking. You ask how many records appear before and after a search string result. That's like asking "What's the difference between an orange?" -- it doesn't make sense.

The user enters a search string. All records are searched and the correct one is found and presented. Now you want the records that were not correct to be arranged in some manner of before and after correctness -- it doesn't make sense.

You could use a FULL TEXT search in order of relevance, much like what search engines do. But those searches come back with correct searches and then sort them in terms of relevance. They don't show the correct record and then all the records that were before and after correctness. Do you see what I mean?

You could put in a field that has a number assigned to it, and show what numbers came before and after the record selected (like sequence of entry, auto-incrementing ID ), but that isn't relevant to the original search criteria.

You need to think about what you specifically want to show the user -- what would make sense, or of use, to them?

hth's

tedd

--- End Message ---
--- Begin Message ---
On Sat, 2006-12-23 at 11:05 -0500, tedd wrote:
>
> In my opinion, wrong thinking. You ask how many records appear before 
> and after a search string result. That's like asking "What's the 
> difference between an orange?" -- it doesn't make sense.

It makes perfect sense. He has an order to his universe of items. The
search criteria pull out a subset of his universe and he wants to know
where in the universe any given item normally lies.

This is akin to asking I want all words from the dictionary that have
monster in their definition, then look at the word Yeti and saying ok,
now where does Yeti lie with respect to all other words.

Now to provide the answer he wants... AFAIK you need to select all items
from the table and populate into a temporary table with auto increment.
Then select the item in question and it's temporary ID from the
temporary table.

This question comes up every once in a while, I've yet to need such a
feature, and preferrably will never need it since it's not a convenient
solution to select the entire table... but maybe there's a better
solution.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
At 11:24 AM -0500 12/23/06, Robert Cummings wrote:
On Sat, 2006-12-23 at 11:05 -0500, tedd wrote:

 In my opinion, wrong thinking. You ask how many records appear before
 and after a search string result. That's like asking "What's the
 difference between an orange?" -- it doesn't make sense.

It makes perfect sense. He has an order to his universe of items. The
search criteria pull out a subset of his universe and he wants to know
where in the universe any given item normally lies.

Okay, but in what order? Numerically, alphabetically, temporally (time entered, time last altered), likeness, length, height, width, weight, density, color, or what? You need to measure the item to others in some frame of reference.

This is akin to asking I want all words from the dictionary that have
monster in their definition, then look at the word Yeti and saying ok,
now where does Yeti lie with respect to all other words.

Again, in my opinion, that's fuzzy thinking. Sure, Yeti may be in the monster sub-set, but how much monster it is as compared to Lockness? You need a means, a yardstick, to compare the two with each other. Like, is Lockness bigger than the Yeti while monster-mouse is smaller, or what?

Now to provide the answer he wants... AFAIK you need to select all items
from the table and populate into a temporary table with auto increment.
Then select the item in question and it's temporary ID from the
temporary table.

Sure, if you can decide on what bases to select and sort the other items to populate the table.

Cheers,

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

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

I have this php script of 3,500 lines with a big switch that is such that on 
each pass maybe 300 lines of codes are executed at most. The current speed 
of the file is ok. I like to keep the file like that because at each pass 
there is a check on the whole script and it fails if there is a typo 
somewhere. Also, I like to have one file instead of many files. But I am 
wondering if speed is not severaly hurt. What are the general guidelines in 
terms 
of length of script?

Also, I am writing things like that:
    echo '<table>';
    echo '<tr>';
    echo "<td>Content</td>";
    echo '</tr>';
    echo '</table>';

I like it this way because the script is visually very well aligned, with one 
action 
per line and that makes things easier for me to read and understand. But, so 
many echoes may be considered bad practice; maybe it impacts speed 
significantly.
Thanks

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message --- I would assume it does, since parsing each instruction and calling the internal functions to execute each echo should take time. I would use heredoc, which would allow you to make a single call and still keep the formatting of the string.

You might also be interested in my own plugin to the Php Compiler which does just that, it compacts consecutive echos: http://satyam.com.ar/pht/compacting_echos.htm. This is a pre-compiler, it produces a new PHP source which will be the one interpreted. This new source is not quite legible as you wish, but it is not meant to be, all the nice formatting for the echo is lost, but it is not a source to be mantained, you would still use the originals to edit, the output of the pre-compiler to execute. So, you would be able to format the echoes in the source in whichever way you wish, the pre-compiler plugin would take care of compacting them for speed.

Notice that the pre-compiler itself can use my plugin or any other anybody might develop and I would encourage people in this list to do so. The plugin to compact echos was a consequence of the plugin I meant to do, which you will find at http://satyam.com.ar/pht/, which produced a large number of echos and so it almost forced me to do something about them. I never thought about other possible compile-time optimizations, but if anyone does, the Php Compiler is a wonderful platform to do them.

I am sure you will also get a lot of replies sugesting template engines such as Smarty.

Satyam



----- Original Message ----- From: "Jean-Christophe Roux" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, December 23, 2006 7:33 PM
Subject: [PHP] Script's length, echo, and execution speed


Hello,

I have this php script of 3,500 lines with a big switch that is such that on
each pass maybe 300 lines of codes are executed at most. The current speed
of the file is ok. I like to keep the file like that because at each pass
there is a check on the whole script and it fails if there is a typo
somewhere. Also, I like to have one file instead of many files. But I am
wondering if speed is not severaly hurt. What are the general guidelines in terms
of length of script?

Also, I am writing things like that:
   echo '<table>';
   echo '<tr>';
   echo "<td>Content</td>";
   echo '</tr>';
   echo '</table>';

I like it this way because the script is visually very well aligned, with one action
per line and that makes things easier for me to read and understand. But, so
many echoes may be considered bad practice; maybe it impacts speed
significantly.
Thanks

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--- End Message ---
--- Begin Message ---
At 12/23/2006 10:33 AM, Jean-Christophe Roux wrote:
Hello, I have this php script of 3,500 lines with a big switch that is such that on each pass maybe 300 lines of codes are executed at most. The current speed of the file is ok. I like to keep the file like that because at each pass there is a check on the whole script and it fails if there is a typo somewhere. Also, I like to have one file instead of many files. But I am wondering if speed is not severaly hurt. What are the general guidelines in terms of length of script? Also, I am writing things like that: echo '<table>'; echo '<tr>'; echo "<td>Content</td>"; echo '</tr>'; echo '</table>'; I like it this way because the script is visually very well aligned, with one action per line and that makes things easier for me to read and understand. But, so many echoes may be considered bad practice; maybe it impacts speed significantly.


Are you encountering a speed problem or just pondering this theoretically? My guess is that ECHO 'TEXT'; is one of the fastest, most optimized operations the PHP interpreter executes.

But you don't need to guess at it: time it. Check the server logs, or output the current time at the beginning and end of script execution. My guess is that the difference between the execution of your script and one much smaller will lie in a scale of tens or hundreds of milliseconds. Servers are bloody fast; that's their job.

In general I think it's smarter to spend your time making your script easy to read and proofread for you, the human slow link in the development chain, than it is to make it faster to run on a machine. Machines will keep getting faster; you're not likely to.

That said, there are things you can do that make your script more efficient to execute AND to maintain. Personally I favor separating out the HTML into larger, pure chunks that can be proofread more easily than when tags and attributes are atomized and strewn throughout the logic.

Regards,
Paul
--- End Message ---
--- Begin Message ---
Yeah, try testing. Maybe something like this:
<?php
$form = "<form action=' ' method='post'><textarea
name='code'></textarea><br /><button
type='submit'>Execute</button></form>";
if ($_POST['code']) {
 echo "<div style='border: 1px'>";
  $time_start = microtime_float();
  eval($_POST['code']);
  $time_end = microtime_float();
 echo "<br />Loading took: ". $time_end - $time_start. '</div>';
 }
echo "<div style='float: left'>$form</div>";
// Note: This script is extremely dangerous and is not tested.
?>

On 12/23/06, Paul Novitski <[EMAIL PROTECTED]> wrote:
At 12/23/2006 10:33 AM, Jean-Christophe Roux wrote:
>Hello, I have this php script of 3,500 lines with a big switch that
>is such that on each pass maybe 300 lines of codes are executed at
>most. The current speed of the file is ok. I like to keep the file
>like that because at each pass there is a check on the whole script
>and it fails if there is a typo somewhere. Also, I like to have one
>file instead of many files. But I am wondering if speed is not
>severaly hurt. What are the general guidelines in terms of length of
>script? Also, I am writing things like that:     echo
>'<table>';     echo '<tr>';     echo "<td>Content</td>";     echo
>'</tr>';     echo '</table>'; I like it this way because the script
>is visually very well aligned, with one action per line and that
>makes things easier for me to read and understand. But, so many
>echoes may be considered bad practice; maybe it impacts speed significantly.


Are you encountering a speed problem or just pondering this
theoretically?  My guess is that ECHO 'TEXT'; is one of the fastest,
most optimized operations the PHP interpreter executes.

But you don't need to guess at it: time it.  Check the server logs,
or output the current time at the beginning and end of script
execution.  My guess is that the difference between the execution of
your script and one much smaller will lie in a scale of tens or
hundreds of milliseconds.  Servers are bloody fast; that's their job.

In general I think it's smarter to spend your time making your script
easy to read and proofread for you, the human slow link in the
development chain, than it is to make it faster to run on a
machine.  Machines will keep getting faster; you're not likely to.

That said, there are things you can do that make your script more
efficient to execute AND to maintain.  Personally I favor separating
out the HTML into larger, pure chunks that can be proofread more
easily than when tags and attributes are atomized and strewn
throughout the logic.

Regards,
Paul

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



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


Casey Chu wrote:
> 
> Yeah, try testing. Maybe something like this:
> <?php
>  $form = "<form action=' ' method='post'><textarea
> name='code'></textarea><br /><button
> type='submit'>Execute</button></form>";
>  if ($_POST['code']) {
>   echo "<div style='border: 1px'>";
>    $time_start = microtime_float();
>    eval($_POST['code']);
>    $time_end = microtime_float();
>   echo "<br />Loading took: ". $time_end - $time_start. '</div>';
>   }
>  echo "<div style='float: left'>$form</div>";
>  // Note: This script is extremely dangerous and is not tested.
> ?>
> 
> 

under php5 use can use microtime(1) for timestamps
-- 
View this message in context: 
http://www.nabble.com/Script%27s-length%2C-echo%2C-and-execution-speed-tf2875055.html#a8037132
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
Casey Chu wrote:
Yeah, try testing. Maybe something like this:
<?php
$form = "<form action=' ' method='post'><textarea
name='code'></textarea><br /><button
type='submit'>Execute</button></form>";
if ($_POST['code']) {
 echo "<div style='border: 1px'>";
  $time_start = microtime_float();
  eval($_POST['code']);
  $time_end = microtime_float();
 echo "<br />Loading took: ". $time_end - $time_start. '</div>';
 }
echo "<div style='float: left'>$form</div>";
// Note: This script is extremely dangerous and is not tested.
?>
I haven't been following this thread, so I don't know if this has been suggested...

If you can run a local server, IMO, xdebug is *the* way to go...xdebug2 has an excellent profiler built-in. You can use kcachegrind or wincachegrind to see some pretty mind-boggling detail about where your performance goes. It's much easier than inserting timing statements into existing code.

jon

--- End Message ---
--- Begin Message ---
What do you mean by "now"?

On 12/22/06, JMCS Niagara (Jeff) <[EMAIL PROTECTED]> wrote:
hi there. I'm looking to create a new user signup. So when someone signs up, it 
emails admin the Username, Real Name, and IP address.

I have this code called newusersignupnotification.php

<?php
$to = '[EMAIL PROTECTED]'; // The email address you want the notification sent 
to
$subject = 'Member has registered on YoS'; // What do you want the subject line 
of your notification to be?
$memberSpecs =
"<hr size=2 width=300 align=left>".
"<b>Username:</b> ".$_SESSION['username'].
"<br>".
"<b>Real Name:</b> ".$_SESSION['firstname']. " ".$_SESSION['lastname'].
"<br>".
"<b>Date</b> ".date('l dS \of F Y h:i:s A').
"<br>".
"<b>IP address:</b> ".$_SERVER['REMOTE_ADDR'].
"<br>".
"<b>System Specs:</b> ".$_SERVER['HTTP_USER_AGENT'].
"<br>";
$headers = "Content-type: text/html \nFrom: [EMAIL PROTECTED]";
$body = "<body>
<br>
<table cellspacing=1 cellpadding=2 align=center>
<tr>
<td>
<b><font face=arial size=2>A new member has registered! </font></b>

</td></tr>
<tr>
<td>
<font face=arial size=2> ".$memberSpecs." </font>
</td></tr></table>
</body>";
mail($to,$subject,$body,$headers);
?>

When I place this in the "join.php" file .. When someone goes to join.php it 
automatically emails it .. and I get date, time, ip, etc etc everything except for the 
username and first name.. Obviously, because the person hasn't typed in anything.

When they filled out the sign up form, There's a button that says Sign Up .. 
Basically, when they click this button, NOW is when I want it to email me the 
details.

Any ideas?

Thanks guys


--- End Message ---
--- Begin Message ---
I still do not understand. Isn't that what your script already does?

On 12/23/06, Casey Chu <[EMAIL PROTECTED]> wrote:
What do you mean by "now"?

On 12/22/06, JMCS Niagara (Jeff) <[EMAIL PROTECTED]> wrote:
> hi there. I'm looking to create a new user signup. So when someone signs up, 
it emails admin the Username, Real Name, and IP address.
>
> I have this code called newusersignupnotification.php
>
> <?php
> $to = '[EMAIL PROTECTED]'; // The email address you want the notification 
sent to
> $subject = 'Member has registered on YoS'; // What do you want the subject 
line of your notification to be?
> $memberSpecs =
> "<hr size=2 width=300 align=left>".
> "<b>Username:</b> ".$_SESSION['username'].
> "<br>".
> "<b>Real Name:</b> ".$_SESSION['firstname']. " ".$_SESSION['lastname'].
> "<br>".
> "<b>Date</b> ".date('l dS \of F Y h:i:s A').
> "<br>".
> "<b>IP address:</b> ".$_SERVER['REMOTE_ADDR'].
> "<br>".
> "<b>System Specs:</b> ".$_SERVER['HTTP_USER_AGENT'].
> "<br>";
> $headers = "Content-type: text/html \nFrom: [EMAIL PROTECTED]";
> $body = "<body>
> <br>
> <table cellspacing=1 cellpadding=2 align=center>
> <tr>
> <td>
> <b><font face=arial size=2>A new member has registered! </font></b>
>
> </td></tr>
> <tr>
> <td>
> <font face=arial size=2> ".$memberSpecs." </font>
> </td></tr></table>
> </body>";
> mail($to,$subject,$body,$headers);
> ?>
>
> When I place this in the "join.php" file .. When someone goes to join.php it 
automatically emails it .. and I get date, time, ip, etc etc everything except for the 
username and first name.. Obviously, because the person hasn't typed in anything.
>
> When they filled out the sign up form, There's a button that says Sign Up .. 
Basically, when they click this button, NOW is when I want it to email me the 
details.
>
> Any ideas?
>
> Thanks guys
>


--- End Message ---
--- Begin Message ---
Casey Chu wrote:
I still do not understand. Isn't that what your script already does?

On 12/23/06, Casey Chu <[EMAIL PROTECTED]> wrote:
What do you mean by "now"?

On 12/22/06, JMCS Niagara (Jeff) <[EMAIL PROTECTED]> wrote:
> hi there. I'm looking to create a new user signup. So when someone signs up, it emails admin the Username, Real Name, and IP address.
>
> I have this code called newusersignupnotification.php
>
> <?php
> $to = '[EMAIL PROTECTED]'; // The email address you want the notification sent to > $subject = 'Member has registered on YoS'; // What do you want the subject line of your notification to be?
> $memberSpecs =
> "<hr size=2 width=300 align=left>".
> "<b>Username:</b> ".$_SESSION['username'].
> "<br>".
> "<b>Real Name:</b> ".$_SESSION['firstname']. " ".$_SESSION['lastname'].
> "<br>".
> "<b>Date</b> ".date('l dS \of F Y h:i:s A').
> "<br>".
> "<b>IP address:</b> ".$_SERVER['REMOTE_ADDR'].
> "<br>".
> "<b>System Specs:</b> ".$_SERVER['HTTP_USER_AGENT'].
> "<br>";
> $headers = "Content-type: text/html \nFrom: [EMAIL PROTECTED]";
> $body = "<body>
> <br>
> <table cellspacing=1 cellpadding=2 align=center>
> <tr>
> <td>
> <b><font face=arial size=2>A new member has registered! </font></b>
>
> </td></tr>
> <tr>
> <td>
> <font face=arial size=2> ".$memberSpecs." </font>
> </td></tr></table>
> </body>";
> mail($to,$subject,$body,$headers);
> ?>
>
> When I place this in the "join.php" file .. When someone goes to join.php it automatically emails it .. and I get date, time, ip, etc etc everything except for the username and first name.. Obviously, because the person hasn't typed in anything.
>
> When they filled out the sign up form, There's a button that says Sign Up .. Basically, when they click this button, NOW is when I want it to email me the details.
>
> Any ideas?
>
> Thanks guys
>


If the user is clicking a sumbit button, the easiest way would be to put at the top:

if($_REQUEST["Submit"] == "whatever your button says"){ mail(blah);
   // process the signup or redirect to the next page.
}

rest of join.php goes here.

Note: You will have to make the submit button action join.php.

--- End Message ---
--- Begin Message ---
Dear PHP community,

I'd like to announce the first public realease of GeryEngine (GE).
GeryEngine is a powerful PHP5 template engine. GE is a port of the well
known Java template engine Velocity with some extra functionality on board,
like inline expressions. GE uses a plain and powerful syntax that can be
mixed in your HTML code.

Example:

<html>
        #set($engine = "GeryEngine 0.2.0")
        <b>$engine.reverse.upcase</b>
</html>

More information can be found at:
http://geryengine.instant-publishing.nl/

Regards,
Arjen Brouwer

--- End Message ---

Reply via email to