Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7937479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:32:05+00:00 2026-06-03T22:32:05+00:00

I want to delete record from mysql in hierarchical manner. i have my database

  • 0

I want to delete record from mysql in hierarchical manner.
i have my database like this

id pid
1 0
2 1
3 2

i want to delete all above record. please reply with proper function in php mysql.

function content_deleted($content_id=0, $parent_id=0)
    {
        if($parent_id==0)
        {
            $query = $this->db->query("SELECT content_id FROM tbl_content WHERE content_id = $content_id");
        }
        else
        {
            $query = $this->db->query("SELECT content_id FROM tbl_content WHERE content_parent_id = $content_id");  
        }

        if($query->num_rows()>0)
        {
            foreach($query->result() as $res)
            {
                $id = $res->content_id;
                if($parent_id==0)
                {
                    $this->db->query("DELETE FROM tbl_content WHERE content_id = $id"); 
                }
                else
                {
                    $this->db->query("DELETE FROM tbl_content WHERE content_parent_id = $id");
                    $this->content_deleted($content_id, $id);   
                }
            }   
        }
    } 

this is my function im stucked here it onnly delete one record

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:32:06+00:00Added an answer on June 3, 2026 at 10:32 pm

    Relational databases do not lend themselves easily to tree structures. If you only have id and parent_id fields, you’ll have to do a lot of looping and recursion to work with trees. That’s why Nested Sets or MPTT were invented. You should move to that model for your trees and this question will solve itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete all users from my MySQL database with specified name regardless
I want to delete all rows in a datatable. I use something like this:
I want to know how to delete records from a MySQL Database after 1
If I delete a record from the Parent table I want the corresponding records
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
I want to use cursor to delete record from table. How can I do
Possible Duplicate: MySQL delete row from multiple tables I have 5 tables: members member_videos
I have a string in database (mysql) which is like: {StateId:73,CallTime:\/Date(1336365498912+0500)\/,CallId:1336365489.14157,Target:agi://127.0.0.1}},Profile:{$type:DataWriter.DbProfile, DataWriterObjects,Name:DataService,Provider:mssql,ConnectionString:Data Source=localhost\\mydb; Database=mydb;
I have to write a Stored Procedure to delete record from a table. I
I want to delete records from mysql using php the field name: Week Week

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.