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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Small php error in this code...

    I have this piece of code that takes phone numbers from a table called phone_numbers but which the phone numbers aren't in a table called phone_numbers_sent. The code is working however it generates an error if there is no numbers in the phone _numbers_sent table...

    Here is the code

    PHP Code:
        @mysql_connect($config['dbhost'], $config['dbuser'], $config['dbpass']) or die(mysql_error());
        @
    mysql_select_db($config['dbname']) or die(mysql_error());


        
    //define phone list array
        
    $phone_list = array();


        
    $send mysql_query("select `phone` from phone_number_sent");
        
    $sent = array();
        while(
    $r mysql_fetch_assoc($send)){
            
    $sent[]="'".$r['phone']."'";
        
    //    echo $r['phone'];
        
    }
        
    //    print_r($sent);
     
      
    $sent implode(",",$sent);
      
    //echo $sent;
      
        
    $to_send mysql_query("select * from phone_number where phone NOT IN({$sent})");
        
      
      while(
    $row mysql_fetch_assoc($to_send)){
        
    //    echo $row['phone'];
            
    $phone_list[] = array($row['phone'], $row['source']);
        
    //        print_r($phone_list);
        

    can any body help me figure out the code for this

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change
    PHP Code:
    $sent implode(",",$sent);
      
    //echo $sent;
      
        
    $to_send mysql_query("select * from phone_number where phone NOT IN({$sent})");
        
      
      while(
    $row mysql_fetch_assoc($to_send)){
        
    //    echo $row['phone'];
            
    $phone_list[] = array($row['phone'], $row['source']);
        
    //        print_r($phone_list);
        

    to
    PHP Code:
    if(is_array($sent)){
    $sent implode(",",$sent);
      
    //echo $sent;
      
        
    $to_send mysql_query("select * from phone_number where phone NOT IN({$sent})");
        
      
      while(
    $row mysql_fetch_assoc($to_send)){
        
    //    echo $row['phone'];
            
    $phone_list[] = array($row['phone'], $row['source']);
        
    //        print_r($phone_list);
        
    }  

    btw, are you using a numeric datatype for the field phone_number_sent?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Change
    PHP Code:
    $sent implode(",",$sent);
      
    //echo $sent;
      
        
    $to_send mysql_query("select * from phone_number where phone NOT IN({$sent})");
        
      
      while(
    $row mysql_fetch_assoc($to_send)){
        
    //    echo $row['phone'];
            
    $phone_list[] = array($row['phone'], $row['source']);
        
    //        print_r($phone_list);
        

    to
    PHP Code:
    if(is_array($sent)){
    $sent implode(",",$sent);
      
    //echo $sent;
      
        
    $to_send mysql_query("select * from phone_number where phone NOT IN({$sent})");
        
      
      while(
    $row mysql_fetch_assoc($to_send)){
        
    //    echo $row['phone'];
            
    $phone_list[] = array($row['phone'], $row['source']);
        
    //        print_r($phone_list);
        
    }  

    btw, are you using a numeric datatype for the field phone_number_sent?
    i tryed this but creates a problem becasuse there is 170000 numbers in the phone_number_sent table and it loses the connection to the mySQL database..

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Then, you should make use of LIMIT clause in your SELECT statement.

    Initially, find the total number of rows using function count() and then use a suitable suitable offset, say 100. You could use a loop to dynamically change the offset.
    Last edited by abduraooft; 03-30-2010 at 10:28 AM. Reason: typo :(
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Then, you should make use of LIMIT clause in your SELECT statement.

    Initially, find the total m\number of rows using function count() and then use a suitable suitable offset, say 100. Use a loop to dynamically change the offset.
    wow that sounds complicated.. i just realised i have the phone column is set as char(10) would it be a lot better to set it to int(10)

    would if use alot less memory while executing this query
    select * from phone_number where phone NOT IN({$sent})

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Increase mysql connection time out in php.ini, variable is mysql.connect_timeout.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    I'm curious now. Why are you consistently pulling all records from the DB rather than a small subset of results?


  •  

    Posting Permissions

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