Enjoy an ad free experience by logging in. Not a member yet?
Register .
03-30-2010, 09:26 AM
PM User |
#1
Regular Coder
Join Date: Jun 2009
Posts: 350
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
03-30-2010, 09:38 AM
PM User |
#2
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
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)
03-30-2010, 09:43 AM
PM User |
#3
Regular Coder
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
abduraooft
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..
03-30-2010, 10:04 AM
PM User |
#4
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
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 :(
03-30-2010, 10:16 AM
PM User |
#5
Regular Coder
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
abduraooft
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})
03-30-2010, 02:45 PM
PM User |
#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?
03-30-2010, 03:50 PM
PM User |
#7
Senior Coder
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
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?
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 07:37 PM .
Advertisement
Log in to turn off these ads.