Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-30-2010, 09:26 AM   PM User | #1
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
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
kevinkhan is offline   Reply With Quote
Old 03-30-2010, 09:38 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-30-2010, 09:43 AM   PM User | #3
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
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..
kevinkhan is offline   Reply With Quote
Old 03-30-2010, 10:04 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 03-30-2010 at 10:28 AM.. Reason: typo :(
abduraooft is offline   Reply With Quote
Old 03-30-2010, 10:16 AM   PM User | #5
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
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})
kevinkhan is offline   Reply With Quote
Old 03-30-2010, 02:45 PM   PM User | #6
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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?
masterofollies is offline   Reply With Quote
Old 03-30-2010, 03:50 PM   PM User | #7
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
I'm curious now. Why are you consistently pulling all records from the DB rather than a small subset of results?
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:37 PM.


Advertisement
Log in to turn off these ads.