SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong with this While loop?

    Sooo ... what am I doing wrong? This while statment continues to loop endlessly.

    PHP Code:
    mysql_select_db($database$connection);
         
    $query "SELECT * FROM list";
         
    $query_result mysql_query($query$connection) or die(mysql_error());
         
    $result mysql_fetch_assoc($query_result);
     
         
    $counter 0;
     
         While (
    $counter <= mysql_num_rows($query_result)) {
     
         echo 
    $result['id'] . " ... " $result['f_name'] . " " $result['l_name'] . " ... \n";
         
    flush();
     
         
    $sendsubject $subject;
         
    $sendbody $body;
         echo 
    "sending ......... \n";
         
    mail($result['e_mail'], $sendsubject$sendbody");
     
         echo "
    ok<br>\n";
         flush();
     
         
    $counter++;
         } 
    thanks,
    Rusty

  2. #2
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line:
    PHP Code:
    mail($result['e_mail'], $sendsubject$sendbody"); 
    You have an unneeded quote

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    London, UK.
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an erroneous " in your code:

    PHP Code:
    mail($result['e_mail'], $sendsubject$sendbody"); 
    Change it to:

    PHP Code:
    mail($result['e_mail'], $sendsubject$sendbody); 
    The syntax highlighting on these boards can be quite useful. It points the problem out

    David
    Do you fear the obselescence of the
    metanarrative apparatus of legitimation?

  4. #4
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Wonder where that came from.

    Anyway. That's not the reason cause of the problem. The While loop still loops continously.

    Rusty

  5. #5
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Oslo, Norway
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you checked how many rows you actually do get from your query? As far as I can see there's no endless loop, but the script may run for a long time if you got a lot of rows.

    However, your script doesn't make much sense, since you're just fetching the first row from the database and then printing and mailing this x times.

    A better solution would be like this:
    PHP Code:
    mysql_select_db($database$connection);
    $query "SELECT * FROM list";
    $query_result mysql_query($query$connection) or die(mysql_error());
    while (
    $result mysql_fetch_assoc($query_result)) {
        echo 
    $result['id'] . " ... " $result['f_name'] . " " $result['l_name'] . " ... \n";
        
    flush();
        
    $sendsubject $subject;
        
    $sendbody $body;
        echo 
    "sending ......... \n";
        
    mail($result['e_mail'], $sendsubject$sendbody);
        echo 
    "ok<br>n";
        
    flush();


  6. #6
    SitePoint Member
    Join Date
    Apr 2002
    Location
    Pleasant Hill, CA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I see what I was doing wrong now.

    I had two e-mail addresses in the database for testing. I see why it was only using one and why it was looping.

    The counter piece was unnecessary.

    Thanks,
    Rusty


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •