...

View Full Version : Small php error in this code...



kevinkhan
03-30-2010, 09:26 AM
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


@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

abduraooft
03-30-2010, 09:38 AM
Change
$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

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?

kevinkhan
03-30-2010, 09:43 AM
Change
$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

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.. :(

abduraooft
03-30-2010, 10:04 AM
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.

kevinkhan
03-30-2010, 10:16 AM
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})

masterofollies
03-30-2010, 02:45 PM
Increase mysql connection time out in php.ini, variable is mysql.connect_timeout.

MattF
03-30-2010, 03:50 PM
I'm curious now. Why are you consistently pulling all records from the DB rather than a small subset of results?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum