database and arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

database and arrays

Post by stevestark5000 »

Can I have an example on how to use specific database handling functions for populating arrays from database queries.
MagentoC
Forum Newbie
Posts: 1
Joined: Tue Feb 22, 2011 11:22 pm
Location: California

Re: database and arrays

Post 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 ??
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: database and arrays

Post by stevestark5000 »

looks good. thank you.
Post Reply