While Loop Question...

This is a discussion on While Loop Question... within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All I'm trying to create a loop in PHP which will do the following for me :- 1. Get ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-23-2006
GM
 
Posts: n/a
Default While Loop Question...

Hi All

I'm trying to create a loop in PHP which will do the following for me :-

1. Get a count of rows from a table where the current time is greater than
the expired_time.
2. Based on that, we need to get the customercode from that table, to be
able to get an e-mail address from another table where the customercode
matches.
3. Send a notification to the email address to inform the client that the
time has expired.

For now, I have left out the e-mail address part as well as the actual
e-mail sending part. I guess that will happen in the same loop. For now, I
am just trying to get a list of the customercodes. Don't know if i'm on the
right track here...

<?
include "../includes/mysqlcon.php";
echo "hello...";

$current_time = date("Y-m-d H:i:s");

$count = mysql_query("SELECT count(nid) FROM nack_ack where '$current_time'
> date_expired");

$numrows = mysql_num_rows($count);

$i = 1;

while ($i <= $numrows) {

$querycustomercode = mysql_fetch_row(mysql_query("SELECT * from nack_ack
WHERE nid = '$i'"));
$customercode = $querycustomercode[1];

echo $customercode;

}
?>


Reply With Quote
  #2 (permalink)  
Old 01-23-2006
Tim Streater
 
Posts: n/a
Default Re: While Loop Question...

In article <dr25dm$jpf$1@ctb-nnrp2.saix.net>, "GM" <maillist@gam.co.za>
wrote:

> Hi All
>
> I'm trying to create a loop in PHP which will do the following for me :-
>
> 1. Get a count of rows from a table where the current time is greater than
> the expired_time.
> 2. Based on that, we need to get the customercode from that table, to be
> able to get an e-mail address from another table where the customercode
> matches.
> 3. Send a notification to the email address to inform the client that the
> time has expired.
>
> For now, I have left out the e-mail address part as well as the actual
> e-mail sending part. I guess that will happen in the same loop. For now, I
> am just trying to get a list of the customercodes. Don't know if i'm on the
> right track here...
>
> <?
> include "../includes/mysqlcon.php";
> echo "hello...";
>
> $current_time = date("Y-m-d H:i:s");
>
> $count = mysql_query("SELECT count(nid) FROM nack_ack where '$current_time'
> > date_expired");

> $numrows = mysql_num_rows($count);
>
> $i = 1;
>
> while ($i <= $numrows) {
>
> $querycustomercode = mysql_fetch_row(mysql_query("SELECT * from nack_ack
> WHERE nid = '$i'"));
> $customercode = $querycustomercode[1];
>
> echo $customercode;
>
> }
> ?>


You are not incrementing $i in the loop anywhere, so it will run forever.

-- tim
Reply With Quote
  #3 (permalink)  
Old 01-23-2006
J.O. Aho
 
Posts: n/a
Default Re: While Loop Question...

GM wrote:
> Hi All
>
> I'm trying to create a loop in PHP which will do the following for me :-
>
> 1. Get a count of rows from a table where the current time is greater than
> the expired_time.
> 2. Based on that, we need to get the customercode from that table, to be
> able to get an e-mail address from another table where the customercode
> matches.
> 3. Send a notification to the email address to inform the client that the
> time has expired.
>
> For now, I have left out the e-mail address part as well as the actual
> e-mail sending part. I guess that will happen in the same loop. For now, I
> am just trying to get a list of the customercodes. Don't know if i'm on the
> right track here...
>
> <?
> include "../includes/mysqlcon.php";
> echo "hello...";
>
> $current_time = date("Y-m-d H:i:s");
>
> $count = mysql_query("SELECT count(nid) FROM nack_ack where '$current_time'
> > date_expired");

> $numrows = mysql_num_rows($count);
>
> $i = 1;
>
> while ($i <= $numrows) {
>
> $querycustomercode = mysql_fetch_row(mysql_query("SELECT * from nack_ack
> WHERE nid = '$i'"));
> $customercode = $querycustomercode[1];
>
> echo $customercode;
>
> }
> ?>
>
>


<?
include "../includes/mysqlcon.php";
echo "hello...";

$current_time = date("Y-m-d H:i:s");

$count = mysql_query("SELECT count(nid) FROM nack_ack where '$current_time' >
date_expired");
$numrows = mysql_num_rows($count);

$querycustomercode = mysql_query("SELECT * from nack_ack WHERE nid <
'$numrows' ORDER BY nid ASC");

while($row=mysql_fetch_row($querycustomercode)) {
$customercode = $row[1];
echo $customercode;
}
?>



//Aho
Reply With Quote
  #4 (permalink)  
Old 01-23-2006
GM
 
Posts: n/a
Default Re: While Loop Question...

Thanx guys

I sorted out the problem.


Regards

GM






"Tim Streater" <tim.streater@dante.org.uk> wrote in message
news:tim.streater-3043D7.11520223012006@individual.net...
> In article <dr25dm$jpf$1@ctb-nnrp2.saix.net>, "GM" <maillist@gam.co.za>
> wrote:
>
>> Hi All
>>
>> I'm trying to create a loop in PHP which will do the following for me :-
>>
>> 1. Get a count of rows from a table where the current time is greater
>> than
>> the expired_time.
>> 2. Based on that, we need to get the customercode from that table, to be
>> able to get an e-mail address from another table where the customercode
>> matches.
>> 3. Send a notification to the email address to inform the client that the
>> time has expired.
>>
>> For now, I have left out the e-mail address part as well as the actual
>> e-mail sending part. I guess that will happen in the same loop. For now,
>> I
>> am just trying to get a list of the customercodes. Don't know if i'm on
>> the
>> right track here...
>>
>> <?
>> include "../includes/mysqlcon.php";
>> echo "hello...";
>>
>> $current_time = date("Y-m-d H:i:s");
>>
>> $count = mysql_query("SELECT count(nid) FROM nack_ack where
>> '$current_time'
>> > date_expired");

>> $numrows = mysql_num_rows($count);
>>
>> $i = 1;
>>
>> while ($i <= $numrows) {
>>
>> $querycustomercode = mysql_fetch_row(mysql_query("SELECT * from nack_ack
>> WHERE nid = '$i'"));
>> $customercode = $querycustomercode[1];
>>
>> echo $customercode;
>>
>> }
>> ?>

>
> You are not incrementing $i in the loop anywhere, so it will run forever.
>
> -- tim



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:13 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0