Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Limit While Loop

    Code:
    <?php
    
    while($row = mysql_fetch_array($result))
      {
    
      $tmhOAuth = new tmhOAuth(array(
      'consumer_key'    => $theconkeys['conkey'],
      'consumer_secret' => $theconkeys['consecret'],
      'user_token'      => $row['token'],
      'user_secret'     => $row['secret'],
    ));
    
    
    
    
    }
      
    ?>
    how do i limit this while loop.... im lost

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by phillypro View Post
    Code:
    <?php
    
    while($row = mysql_fetch_array($result))
      {
    
      $tmhOAuth = new tmhOAuth(array(
      'consumer_key'    => $theconkeys['conkey'],
      'consumer_secret' => $theconkeys['consecret'],
      'user_token'      => $row['token'],
      'user_secret'     => $row['secret'],
    ));
    }
      
    ?>
    how do i limit this while loop.... im lost
    what do you mean by 'limit'?

    best regards

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    If you know how many iterations the while loop will go through, then another option is to use a FOR loop instead.

    Otherwise, another option is to put a test condition inside the while loop and if it returns a specified value during an iteration, break out of the while loop.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by bullant View Post
    If you know how many iterations the while loop will go through, then another option is to use a FOR loop instead.

    Otherwise, another option is to put a test condition inside the while loop and if it returns a specified value during an iteration, break out of the while loop.
    why to fetch a lot of data from mysql instead of use 'limit 1' in query?
    btw, we don't realy know what op means by 'limit', maybe he/she want to limit data to some oauth secret/private keys or something else,

    best regards

  • #5
    New Coder
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry i was so unclear fellas

    basically

    I have a database....full of names

    i load all the rows of the table and define it as a variable

    then i use the while loop to run commands on each table row ...till it reaches the end


    what i want to do...is somehow work in a function where i can specify how many tables rows get loaded into the variable seems the more appropriate question

  • #6
    New Coder
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <?php 
    require_once('inc/twitterOAuth.php');
    require_once('inc/tmhOAuth.php');
    require_once('connector.php');
    
    
    
    
    
    $result = mysql_query("SELECT * FROM twitter");
    
    $follow=$_POST['follow'];
    
    
    
    echo '<b class="progress_title">In Progress </b><div class="results">'; ?>
    
    <?php
    
    while($row = mysql_fetch_array($result))
      {
    
      $tmhOAuth = new tmhOAuth(array(
      'consumer_key'    => $theconkeys['conkey'],
      'consumer_secret' => $theconkeys['consecret'],
      'user_token'      => $row['token'],
      'user_secret'     => $row['secret'],
    ));
    
    
    
    echo  '@'.$row['name'];
    echo '<br />';
    
    }
      
    ?>
      
      
      
    <?php echo '</div>';
    
    echo  '<form method="post">
    <input type="button" value="End Process"
    onclick="window.close()">
    </form>';
    
    mysql_close($con);  
      
    ?>
    this is my current code


    also...you think theres any way to time delay the loop?....add a couple seconds before it processes the next tabel row?

  • #7
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by phillypro View Post
    also...you think theres any way to time delay the loop?....add a couple seconds before it processes the next tabel row?
    Wha? Why would you want to do *that*?

  • #8
    New Coder
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    1
    Thanked 0 Times in 0 Posts
    because certain actions need 5 seconds or so inbetween to look realistic...you dont wanna flood something in milliseconds

  • #9
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by oesxyl View Post
    why to fetch a lot of data from mysql instead of use 'limit 1' in query?
    btw, we don't realy know what op means by 'limit', maybe he/she want to limit data to some oauth secret/private keys or something else,

    best regards
    yep, you answered your own question because we're not sure what the op means by limit.

    I described some options and you offered an additional one

  • #10
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by phillypro View Post
    because certain actions need 5 seconds or so inbetween to look realistic...you dont wanna flood something in milliseconds
    What do you mean, "look realistic"? This is PHP. Your browser won't see *any* output, before PHP has finished doing *everything*. So, if you were to introduce a 5 second delay for every row, all you would accomplish would be making the user wait forever before finally getting the page — all at once.

  • #11
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    What do you mean, "look realistic"? This is PHP. Your browser won't see *any* output, before PHP has finished doing *everything*. So, if you were to introduce a 5 second delay for every row, all you would accomplish would be making the user wait forever before finally getting the page — all at once.
    Not quite... you can use sleep() to do the delay, but use flush() before each sleep() so that it instantly sends the output to the browser.

    NBS

  • #12
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    This is the wrong way to influence client side behaviour. Apart from the fact that the server side script shouldn't have to care about that sort of stuff, just read the manual entry for flush() to see what can all go wrong.

  • #13
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    This is the wrong way to influence client side behaviour. Apart from the fact that the server side script shouldn't have to care about that sort of stuff, just read the manual entry for flush() to see what can all go wrong.
    As with any function, of course particular aspects of it can go wrong; I was simply pointing out a potential approach to use, at the original poster's discretion.

    NBS


  •  

    Posting Permissions

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