Welcome Guest, Not a member yet? Register   Sign In
How to empty more than one tabel ?
#1

[eluser]shinokada[/eluser]
I can empty one table by following.

Code:
$this->db->empty_table('mytable');

But I want to empty more than 10 tables.

I tried this.
But it does not work.


Code:
$mytable = array('table1', 'table2', 'table3', ...);
$this->db->empty_table($mytable);

or

$this->db->empty_table('table1','table2','table3',...);

I don't want to do like this. It seems a bit silly.

Code:
$this->db->empty_table('mytable1');
$this->db->empty_table('mytable2');
$this->db->empty_table('mytable3');
$this->db->empty_table('mytable4');
...
...



Could anyone tell me how to empty more than one table?

Thanks in advance.
#2

[eluser]liri[/eluser]
1. Use a loop
Code:
$tables = array('table1', 'table2', 'table3');
foreach($tables as $table)
{
   $this->db->empty_table($table);
}


2. Extend the class, specifically the empty_table() method to accept arrays
as arguments and essentially to the same. (either loop or use the database engine
to perform it if it's supported)




Theme © iAndrew 2016 - Forum software by © MyBB