php-windows Digest 5 Feb 2011 08:20:00 -0000 Issue 3915

Topics (messages 30500 through 30503):

Re: Search engine won't page properly
        30500 by: Tommy Pham
        30501 by: Tommy Pham
        30502 by: Tommy Pham

Re: Problem in sending email from localhost
        30503 by: Niamathullah Sharief

Administrivia:

To subscribe to the digest, e-mail:
        php-windows-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-windows-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-wind...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Previously,

> [CODE]

<snip>
 
> <BODY bgcolor='ivory'>
> 
>    <?php
>          //$s = 14; hard coded as a debug statement
>          $S= @$_GET['$s'] ;

With the above, PHP is looking for the GET parameter name $s, not the value
of $s as the the GET parameter name.  If you want the latter, change it to
$_GET[$s].  IIRC, PHP is not case specific, not like Java and C#.

>    Echo "\$s on line 69 is - $s<BR />"; //debug statement
>    ?>

<snip>

> 
> [/CODE]


On Fri, Feb 4, 2011 at 8:05 AM, Bill Mudry <billmu...@rogers.com> wrote:
> At 12:11 AM 04/02/2011, Tommy Pham wrote:
>
> Bill,
>
> That's a lot of reading ... Anyway, this seems to be a 'general' PHP
> question.  If I understood you correctly, you're having problem getting
PHP
> to page the SQL results?  If so, look the below code logic and adapt as
> necessary:
>
> $numOfResults = 10; // change this to your need
> if( !empty($_GET['page']) && intval($_GET['page']) > 1 ) $currentPage =
> intval($_GET['page']) - 1; // change the $_GET['page'] accordingly
> elseif (!empty($_GET['page']) && strtolower(trim($_GET['page'])) == 'all')
> $currentPage = 'all';
> else $currentPage = 0;
>
> $sqlQuery = 'SELECT * FROM my_table ';
>
> If( $currentPage != 'all' ) $sqlQuery .= ' LIMIT
> '.$currentPage*$numOfResults.', '.$numOfResults; // see [1]
>
> $result = mysql_query($sqlQuery);
>
> Would give you the following:
>
> ?page=all returns all results
> ?page=1 or ?page=0 or ?page= or ?  yields 1st batch $numOfResults ( 1 to
10
> )
> ?page=2 yields 2nd batch $numOfResults ( 11 to 20 )
> ?page=3 yields 3rd batch $numOfResults ( 21 to 30 )
> ?page=4 yields 4th batch $numOfResults ( 31 to 40 )
>
> Etc.... 
>
> Regards,
> Tommy
>
> Perhaps interesting code but when I said including code would help, I was
> referring to
> code for the best way of preserving the record counter, $s, when the
program
> the program
> recycles back on itself on PHP_SELF. As mentioned, at present it does not
> carry forward
> the $s value so it can accumulate with the next page of records and
> therefore gets stuck on
> page one.
>
> Thank you for your effort.
>
> The general code is already there. In fact, if you were to take a closer
> look, it is a fairly
> sophisticated algorithm with a lot of checks and validations. It is also
> very user friendly,
> letting users click on "Next >>" to go ahead one page and "<< Prev" to go
> backward one
> page.
>

I think you're over complicating things.  Paging doesn't depend complicated
code algorithm but rather simple math deductions.  See the below revised
code.

> My testing shows that it should work well IF the value of the record
counter
> would only
> transfer on restarting the page. I will try using SESSION today to see if
it
> will do the job.
>
> Bill Mudry
> Mississauga


Revised code:

$sqlSearchCount = "SELECT COUNT(*) AS Total FROM species WHERE $searchfield
like \"%$querystring%\" order by '$searchfield'";  /*  look into [1] */

$result = mysql_query( $sqlSearchCount );
$totalRows = mysql_fetch_assoc('Total');

$numOfResults = 10;

$maxPages = ceil( $totalRows / $numOfResults );

if( !empty($_GET['page']) )
{
    if( strtolower(trim($_GET['page'])) == 'all' ) 
    {
        $currentPage = 'all';
    }
    else {
        $currentPage = intval($_GET['page']);
        if( $currentPage > $maxPages ) $currentPage = 1;
        elseif ( $currentPage > 1 ) $currentPage--;
        else $currentPage = 1;
    }
}
else $currentPage = 0;

$sqlSearch = "SELECT * FROM species WHERE $searchfield like
\"%$querystring%\" order by '$searchfield'";

if( $currentPage != 'all' ) $sqlSearch .= ' LIMIT
'.($currentPage-1)*$numOfResults.', '.$numOfResults;

$result = mysql_query( $sqlSearch );
/* code to display $result */

if( $currentPage > 1 ) echo '<a href="?page='.$currentPage -
1.'">Previous</a>';
if( $currentPage < $maxPages ) echo '<a href="?page='.$currentPage +
1.'">Next</a>';
if( $totalRows > 0 ) echo 'Showing '.($currentPage - 1)*$numOfResults+1.' to
'.( $currentPage < $maxPages ) ? ( $currentPage )*$numOfResults : $totalRows
.' of total: '.$totalRows;

NOTE:  The code is not tested, but rather quickly cranked out based on
logic.

Regards,
Tommy

[1] http://php.net/mysql_escape_string



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tommy Pham [mailto:tommy...@gmail.com]
> Sent: Friday, February 04, 2011 3:49 PM
> To: 'Bill Mudry'
> Cc: 'php-wind...@lists.php.net'
> Subject: RE: [PHP-WIN] Search engine won't page properly
> 
> 
> Previously,
> 
> > [CODE]
> 
> <snip>
> 
> > <BODY bgcolor='ivory'>
> >
> >    <?php
> >          //$s = 14; hard coded as a debug statement
> >          $S= @$_GET['$s'] ;
> 
> With the above, PHP is looking for the GET parameter name $s, not the
> value of $s as the the GET parameter name.  If you want the latter, change
it
> to $_GET[$s].  IIRC, PHP is not case specific, not like Java and C#.
> 
> >    Echo "\$s on line 69 is - $s<BR />"; //debug statement
> >    ?>
> 
> <snip>
> 
> >
> > [/CODE]
> 
> 
> On Fri, Feb 4, 2011 at 8:05 AM, Bill Mudry <billmu...@rogers.com> wrote:
> > At 12:11 AM 04/02/2011, Tommy Pham wrote:
> >
> > Bill,
> >
> > That's a lot of reading ... Anyway, this seems to be a 'general' PHP
> > question.  If I understood you correctly, you're having problem
> > getting PHP to page the SQL results?  If so, look the below code logic
> > and adapt as
> > necessary:
> >
> > $numOfResults = 10; // change this to your need if(
> > !empty($_GET['page']) && intval($_GET['page']) > 1 ) $currentPage =
> > intval($_GET['page']) - 1; // change the $_GET['page'] accordingly
> > elseif (!empty($_GET['page']) && strtolower(trim($_GET['page'])) ==
> > 'all') $currentPage = 'all'; else $currentPage = 0;
> >
> > $sqlQuery = 'SELECT * FROM my_table ';
> >
> > If( $currentPage != 'all' ) $sqlQuery .= ' LIMIT
> > '.$currentPage*$numOfResults.', '.$numOfResults; // see [1]
> >
> > $result = mysql_query($sqlQuery);
> >
> > Would give you the following:
> >
> > ?page=all returns all results
> > ?page=1 or ?page=0 or ?page= or ?  yields 1st batch $numOfResults ( 1
> > to 10
> > )
> > ?page=2 yields 2nd batch $numOfResults ( 11 to 20 )
> > ?page=3 yields 3rd batch $numOfResults ( 21 to 30 )
> > ?page=4 yields 4th batch $numOfResults ( 31 to 40 )
> >
> > Etc....
> >
> > Regards,
> > Tommy
> >
> > Perhaps interesting code but when I said including code would help, I
> > was referring to code for the best way of preserving the record
> > counter, $s, when the program the program recycles back on itself on
> > PHP_SELF. As mentioned, at present it does not carry forward the $s
> > value so it can accumulate with the next page of records and therefore
> > gets stuck on page one.
> >
> > Thank you for your effort.
> >
> > The general code is already there. In fact, if you were to take a
> > closer look, it is a fairly sophisticated algorithm with a lot of
> > checks and validations. It is also very user friendly, letting users
> > click on "Next >>" to go ahead one page and "<< Prev" to go backward
> > one page.
> >
> 
> I think you're over complicating things.  Paging doesn't depend
complicated
> code algorithm but rather simple math deductions.  See the below revised
> code.
> 
> > My testing shows that it should work well IF the value of the record
> > counter would only transfer on restarting the page. I will try using
> > SESSION today to see if it will do the job.
> >
> > Bill Mudry
> > Mississauga
> 
> 
> Revised code:
> 
> $sqlSearchCount = "SELECT COUNT(*) AS Total FROM species WHERE
> $searchfield like \"%$querystring%\" order by '$searchfield'";  /*  look
into
> [1] */
> 
> $result = mysql_query( $sqlSearchCount ); $totalRows =
> mysql_fetch_assoc('Total');
> 
> $numOfResults = 10;
> 
> $maxPages = ceil( $totalRows / $numOfResults );
> 
> if( !empty($_GET['page']) )
> {
>     if( strtolower(trim($_GET['page'])) == 'all' )
>     {
>         $currentPage = 'all';
>     }
>     else {
>         $currentPage = intval($_GET['page']);
>         if( $currentPage > $maxPages ) $currentPage = 1;
>         elseif ( $currentPage > 1 ) $currentPage--;
>         else $currentPage = 1;
>     }
> }
> else $currentPage = 0;

Sorry, was in hurry to go run an errand didn't have time to review my
e-mail.  That should be else $currentPage = 1;

> 
> $sqlSearch = "SELECT * FROM species WHERE $searchfield like
> \"%$querystring%\" order by '$searchfield'";
> 
> if( $currentPage != 'all' ) $sqlSearch .= ' LIMIT '.($currentPage-
> 1)*$numOfResults.', '.$numOfResults;
> 
> $result = mysql_query( $sqlSearch );
> /* code to display $result */
> 
> if( $currentPage > 1 ) echo '<a href="?page='.$currentPage -
> 1.'">Previous</a>'; if( $currentPage < $maxPages ) echo '<a
> href="?page='.$currentPage + 1.'">Next</a>'; if( $totalRows > 0 ) echo
> 'Showing '.($currentPage - 1)*$numOfResults+1.' to '.( $currentPage <
> $maxPages ) ? ( $currentPage )*$numOfResults : $totalRows .' of total:
> '.$totalRows;
> 
> NOTE:  The code is not tested, but rather quickly cranked out based on
logic.
> 
> Regards,
> Tommy
> 
> [1] http://php.net/mysql_escape_string



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tommy Pham [mailto:tommy...@gmail.com]
> Sent: Friday, February 04, 2011 4:21 PM
> To: 'Bill Mudry'
> Cc: 'php-wind...@lists.php.net'
> Subject: RE: [PHP-WIN] Search engine won't page properly
> 


<snip>

> > $result = mysql_query( $sqlSearchCount ); $totalRows =
> > mysql_fetch_assoc('Total');

Argh... interruptions...  

$row = mysql_fetch_assoc($result);
$totalRows = $row['Total'];

Anyway, you get the idea.

Happy coding,
Tommy


--- End Message ---
--- Begin Message ---
Yes i am using local system, So now i changed as "localhost" instead of
smtp.gmail.com. But still i am getting the below error

*Warning*: mail() [function.mail <http://localhost/function.mail>]: SMTP
> server response: 550-5.7.1 [122.163.25.135] The IP you're using to send mail
> is not authorized to 550-5.7.1 send email directly to our servers. Please
> use the SMTP relay at your 550-5.7.1 service provider instead. Learn more at
> 550 5.7.1 
> http://mail.google.com/support/bin/answer.py?answer=10336he41si4092182ibb.18 
> in
>  *F:\test\xampp\htdocs\sendmail.php* on line*44*


I checked "phpinfo()" also. Its using the correct "php.ini" config file.

I checked this "etstat -ano | moren" command also. Its working fine. So it
shows that my server is working fine. Now i dont know what will be the
error. Anyway i  will post the modified new php.ini mail function part.

*[mail function]*
*; For Win32 only.*
*; http://php.net/smtp*
*SMTP = localhost*
*; http://php.net/smtp-port*
*smtp_port = 25*
*
*
*; For Win32 only.*
*; http://php.net/sendmail-from*
*sendmail_from = xxxxxxx...@gmail.com*
*
*
*
*
*; For Unix only.  You may supply arguments as well (default: "sendmail -t
-i").*
*; http://php.net/sendmail-path*
*;sendmail_path = "\"F:\test\xampp\sendmail\sendmail.exe\" -t"*
*
*
*; Force the addition of the specified parameters to be passed as extra
parameters*
*; to the sendmail binary. These parameters will always replace the value of
*
*; the 5th parameter to mail(), even in safe mode.*
*;mail.force_extra_parameters =*
*
*
*; Add X-PHP-Originating-Script: that will include uid of the script
followed by the filename*
*mail.add_x_header = Off*
*
*
*; Log all mail() calls including the full path of the script, line #, to
address and headers*
*;mail.log = "F:\test\xampp\apache\logs\php_mail.log" *
* *
*
*
Now i dont know what is wrong and why my message is not going....Please help
me

On Thu, Feb 3, 2011 at 7:10 PM, Tommy Pham <tommy...@gmail.com> wrote:

> 1)  Which SMTP server are you trying to use?  On your local system? Or
> smtp.gmail.com?
> 2a) If local system, which are are using?  MS' SMTP or 3rd party like
> hmail?
> Are you sure the server is configured properly and that the service is
> running?  Run this in command prompt:
>
> etstat -ano | moren
>
> You should see something like this:
>
> Proto  Local Address          Foreign Address        State           PID
>  TCP    0.0.0.0:25             0.0.0.0:0              LISTENING       2744
>
> If not, then that's your problem.  You don't have a SMTP server/service
> running.  Notice that last number.  If you're running MS' SMTP, in the
> taskmanager, it should match up with the process inetinfo.exe.  If you're
> using 3rd party, it should match up with their executable.  In the case of
> hmail, it should be hmailserver.exe.
>
> 2b)  If you're using gmail's, from the same system that your PHP code
> resides on, are you able able to connect to the gmail's SMTP using Outlook
> Express to check the validity of the account and no misconfigured
> firewalls/routers (both hardware and software)?
>
> 3)  Run phpinfo();  and check "Loaded Configuration File" to ensure that
> it's loading the right php.ini file.  Sometimes you think it loads the
> right
> one but it doesn't.  Don't assume.  Verify.  Then either scroll down or
> CTRL+F and look for 'SMTP'.  It should be as you configured it, that is if
> it loads the php.ini file from the correct location.
>
> FYI,  I suggest you stay away from non official packaged distributions as
> those tend to put things in places you'll least expect.  Getting the
> official distribution is strongly advised.  It may take you longer to
> understand and get things going.  But in the long run, that knowledge can
> further aid you as you can fine tune the configurations to your specific
> needs and also helps with the troubleshooting of various errors like the
> one
> you're having now.  Furthermore, should the need arise when you have to
> upgrade for any reason, you don't have to rely on non official distribution
> as sometimes those won't be updated quickly enough, especially when there's
> a security bug fix release.
>
> Regards,
> Tommy
>
>

--- End Message ---

Reply via email to