Advanced Search

Results 1 to 8 of 8

Thread: problem deleting particular row record

  1. #1
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default problem deleting particular row record

    hi all

    i am working in admin section to manage records. There i have records from serial no.38 to 43. I have a option to delete each single record with delete button provided with each single record. The problem i m getting in deleting is

    1) when i click delete buton at record no.38 then the record no.43 gets deleted.

    2) Then again when i click delete buton at record no.39 then the record no.41 gets deleted.


    this the code
    Code:
    <?php
    if(isset($_REQUEST['del_item_x']))
    {
    $qry_del="select * from order_detail_table";
    $result_del=mysql_query($qry_del);
    //$row_del=mysql_fetch_array($result_del);
    while($row_del=mysql_fetch_array($result_del))
    {
    $serial=$row_del['serial'];
    $order_id=$row_del['order_id'];
    $product_name=$row_del['product_name'];
    //echo $serial;
    //echo "test". $row_del['order_id'];
    }
    $qry_del="DELETE from order_detail_table where order_id=$order_id AND serial='$serial'";
    echo $qry_del;
    
    if(mysql_query($qry_del))
    {
     $msg="item deleted success";
    }
    else
     {
     $msg="item not deleted";
     }
    } 
    
    ?>

    vineet

  2. #2
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Well i'm not what you can call an expert but what i see...

    You are getting the serial number with the while statement

    PHP Code:
    $qry_del="select * from order_detail_table";
    $result_del=mysql_query($qry_del);
    while(
    $row_del=mysql_fetch_array($result_del))
    {
    $serial=$row_del['serial'];
    $order_id=$row_del['order_id'];
    $product_name=$row_del['product_name'];

    so of course you are gonna get as $serial the last record, so when you are deleting you will be deleting the last.

    You should pass the serial or id from the form and then just do the delete.
    PHP Code:
    $qry_del="DELETE from order_detail_table where order_id=$order_id AND serial='$serial'";
    if(
    mysql_query($qry_del))
    {
     
    $msg="item deleted success";
    }
    else
     {
     
    $msg="item not deleted";
     } 
    I hope it helps, i'm just a newbie

  3. #3
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hi tuga

    the thing is if you solve my problem you are an expert for me. i m also a newbie.

    can u be more clear with this line
    Code:
    You should pass the serial or id from the form and then just do the delete.
    vineet

  4. #4
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I guess that you have a form showing some kind of table with records.

    Then i guess you have some checkbox to select which record(s) to delete, usually i set the value of each box with the id and the name sequencial like name="checkbox1" and so on. Another thing i do is add a hidden field with the record numbers, so know how many records are on the form. So when you do a submit you pass the values you want to delete in the selected checboxes and the total number of records.

    If you show the code for the form maybe i can help you better.

  5. #5
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hi tuga

    actually the rows data is not entered through the form. its getting data inserted from other tables in the database through queries codes. Its a lengthy code otherwise i should have shown you.

    vineet

  6. #6
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by vineet View Post
    hi tuga

    actually the rows data is not entered through the form. its getting data inserted from other tables in the database through queries codes. Its a lengthy code otherwise i should have shown you.

    vineet
    Well i cannot help you much like that.
    When you press the delete button you should somehow pass the id you want to delete,if you do not pass it, how do you know which record to delete?

    This will always fetch the last record if more than one, and not the one you want, unless this retrieves only one record.
    PHP Code:
    $qry_del="select * from order_detail_table";
    $result_del=mysql_query($qry_del);
    while(
    $row_del=mysql_fetch_array($result_del))
    {
    $serial=$row_del['serial'];
    $order_id=$row_del['order_id'];
    $product_name=$row_del['product_name'];


    Sorry

  7. #7
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hi tuga

    i understand you. you are right. i need to get the serial or id to pass.

    when the rows get inserted into the table the serial number gets inserted automatically as its auto increment in database.

    see when i click delete button and echo the qry then i get

    Code:
    delete from order_detail_table where order_id=67 and serial=40
    here is where i m getting the trouble. i m getting the corect order id but i m not gettng the right serial no.

    vineet
    Last edited by vineet; 11-20-2008 at 09:00 AM. Reason: forgot something

  8. #8
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    try this

    PHP Code:
    $qry_del="select * from order_detail_table";
    $result_del=mysql_query($qry_del);
    while(
    $row_del=mysql_fetch_assoc($result_del))
    {
    $serial=$row_del['serial'];
    $order_id=$row_del['order_id'];
    $product_name=$row_del['product_name'];

    the change
    while($row_del=mysql_fetch_assoc($result_del))

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •