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 4100470
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:34:15+00:00 2026-05-20T20:34:15+00:00

this is re: question of question as suggested by Col. Shrapnel to post a

  • 0

this is re: question of question
as suggested by Col. Shrapnel to post a new question with clear contents.

I have a facebook user likes data i.e

{
   "data": [
      {
         "name": "Joker",
         "category": "Public figure"
      },
      {
         "name": "Rafael Nadal",
         "category": "Athlete"
      },
      {
         "name": "Lassi",
         "category": "Company"
      },
      {
         "name": "Jacinda Barrett",
         "category": "Public figure"
      },
      {
         "name": "cocacola",
         "category": "Company"
      },
      {
         "name": "SWEENEY TODD",
         "category": "Movie"
      },
      {
         "name": "The Notebook",
         "category": "Movie"
      },
      {
         "name": "Unforgiven",
         "category": "Movie"
      }
      ]}

i want to count the no of each category (e.g here Movie=3, company=2 etc) and save it in mysql table and i also want to save the
name of each category in other table(i.e for category Movie there should be Movie(id,name) table and same for all categories). what
i have done is


            $movie=0;  // also define all variables here(i.e $company, $public figure etc) so that it would be increamented.
       foreach($like['data'] as $jsondata=>$json)
        {
             if($json['category']==='Movie')
        {
        $name_movie=$json['name'];
        $query1="insert into movies(id,name)values('', '" . mysql_real_escape_string($name_movie). "')";
        $result1=mysql_query($query1) or die("error in query".mysql_error());
        $movie++;   // in the last this $movie++ will be inserted in other table
        }
        else
                    if($json['category']==='company')
                        { do the same steps as above}
                 else
                     .
                     .
                     .
                     //similarly for all others categories

But it seems inefficient as per speed and consistency concern.

My question is am i using the right approach or there should be something else for this cenario.

  • 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-05-20T20:34:15+00:00Added an answer on May 20, 2026 at 8:34 pm

    This is a cleaner version of the code. I rearranged the json data to create an array sorted by category:

    $tables = array('movie', 'company'); //etc
    $categories = array();
    foreach($like['data'] as $jsondata=>$json)
    {
        $categories[$json['category']][] = $json['category'];
    {
    
    foreach($categories as $key => $category)
    {
        if (in_array($key, $tables))
        {
    
            $i = 0;
            foreach($category as $item)
            {
                $query1="insert into " . $key . "(id,name)values('', '" . mysql_real_escape_string($item['name']). "')";
                $result1=mysql_query($query1) or die("error in query".mysql_error());
                $i++;
            }
            $category_count[$key] = $i;
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question over Security site, and people there suggested I should have
Though this question is asked previously but their is no workaround suggested. I have
I have already asked this question on SuperUser but it was suggested there that
In a response to this question runefs suggested that unless you have a very
this question could seem as duplicate, i have tried all the suggested solution but
I have looked at this question which has been suggested as a duplicate: Make
I have seen this question answered a few times in which it is suggested
As suggested in several answers to this question: What is the name of this
In this question about creating a new perl module , it was suggested to
A few days ago I posted this question and everyone suggested me to use

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.