CodeIgniter Forums

Full Version: need help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]pankaj.sharma[/eluser]
hiiii
i am new to codeigniter
i have done fatch data form database ssuccefully
but how i delete row respective to id
plz help me

in core coading i am doing...
<a href="selection.php?todo=&lt;?=$row['id']?&gt;">Delete</a>

and at the top of the program
if(isset($_REQUEST['todo']))
{
$id = $_REQUEST['todo'];
mysql_query("delete from formtable where id = '".$_GET['REQUEST']."' ");
header("locationConfusedelect.php");
}

but how it done in codeigniter
plz help me

El Forum

[eluser]imn.codeartist[/eluser]
Quote:in core coading i am doing…
?&gt;”]Delete

For Delete in CI,

Code:
$this->db->delete();

Generates a delete SQL string and runs the query.
Code:
$this->db->delete('mytable', array('id' => $id));

// Produces:
// DELETE FROM mytable
// WHERE id = $id

The first parameter is the table name, the second is the where clause. You can also use the where() or or_where() functions instead of passing the data to the second parameter of the function:

Code:
$this->db->where('id', $id);
$this->db->delete('mytable');

// Produces:
// DELETE FROM mytable
// WHERE id = $id

An array of table names can be passed into delete() if you would like to delete data from more than 1 table.

Code:
$tables = array('table1', 'table2', 'table3');
$this->db->where('id', '5');
$this->db->delete($tables);

Please follow this url
http://ellislab.com/codeigniter/user-gui...tml#delete

and at the top of the program
if(isset($_REQUEST[‘todo’]))
{
$id = $_REQUEST[‘todo’];
mysql_query(“delete from formtable where id = ‘“.$_GET[‘REQUEST’].”’ “);
header(“locationConfusedelect.php”);
}

but how it done in codeigniter
plz help me

El Forum

[eluser]pankaj.sharma[/eluser]
sir plz give me complete example
what i write in view,controller and model

plz sir
what i write in view
my table name is pankajdb
having 5 element
id,name,fname,city,state

thanks in advanced

El Forum

[eluser]jabga[/eluser]
removed...

El Forum

[eluser]InsiteFX[/eluser]
dixcoder has shown you above how to delete an id using CodeIgniter's Active Record.

You need to read the CodeIgniter user guide here

Database:

Database

As far as your view, you need to read the CodeIgniter form_helper here:

Form Helper

Then read the CodeIgniter Form Validation here:

Form Validation

No one is going to write the whole code for you, you need to start reading the CodeIgniter user guide and try to do a lot of these things on your own!

If you have a specific problem then I am sure that lots of users on here will help you out but to code the whole thing for you I doubt it.

Enjoy
InsiteFX

El Forum

[eluser]n0xie[/eluser]
Also any destructive data manipulation should be done from a POST, not a GET...