Page 1 of 1
database and arrays
Posted: Wed Mar 09, 2011 12:32 am
by stevestark5000
Can I have an example on how to use specific database handling functions for populating arrays from database queries.
Re: database and arrays
Posted: Wed Mar 09, 2011 4:31 am
by MagentoC
$sql_start = ‘INSERT INTO `mytable` VALUES ‘; // We’ll use this at the beginning of each query
$sql_array = array(); // This is where we’ll queue up the rows
$queue_num = 20; // How many rows should be queued at once?
foreach ($_POST['username'] as $row=>$name)
{
$username = $name;
$phonenum = $_POST['phonenum'][$row];
$sql_array[] = ‘(‘ . $username . ‘, ‘ . $phonenum . ‘)’; // Add a new entry to the queue
if (count($sql_array) >= $queue_num)
{ // We have reached the queue limit
mysql_query($sql_start . implode(‘, ‘, $sql_array)); // Insert those that are queued up
$sql_array = array(); // Erase the queue
}
}
if (count($sql_array) > 0) // There are rows left over
{
mysql_query($sql_start . implode(‘, ‘, $sql_array));
}
How abt this one ??
Re: database and arrays
Posted: Wed Mar 09, 2011 6:22 pm
by stevestark5000
looks good. thank you.