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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:13:09+00:00 2026-05-23T04:13:09+00:00

The get_tag_id is bringing back the first array item twice if I enter the

  • 0

The get_tag_id is bringing back the first array item twice if I enter the following:

texture, clients

I get this return:

Array
(
    [0] => texture
    [1] => clients
)
Array
(
    [0] => stdClass Object
        (
            [TagID] => 4
            [Title] => texture
        )

)
Array
(
    [0] => stdClass Object
        (
            [TagID] => 4
            [Title] => texture
        )

)
Array
(
    [0] => stdClass Object
        (
            [TagID] => 1
            [Title] => clients
        )

)
Array
(
    [0] => texture
    [1] => clients
)

Below is the code:

        // Break up Tags and Store in an Array
        $delimiter = " ";
        $tags = explode($delimiter, $this->input->post('tags'));

        // Remove Accidential Spaces if any.
        $tags = array_filter($tags, function($var){
             return preg_match('/^[a-z-]+$/i', $var);
        });

        // Create Arrays for Seperation
        $newTags = array();
        $currentTags = array();
        print_r($tags);

        // Check if Tags Exists
        foreach ($tags as $tag) 
        {
            if (!$this->Bookmark_model->tag_exists($tag))
            {
                array_push($currentTags, strtolower($tag));
                // Get ID of tags that are existing
                foreach ($currentTags as $tagname) 
                {
                    $id = $this->Bookmark_model->get_tag_id($tagname);
                    echo $id;
                }
            }
            else
            {
                array_push($newTags, strtolower($tag));
            }
        }

get_tag_id() code:

function get_tag_id($tag)
{
    // Load Database
    $this->load->database();
    // Query Database
    $this->db->where_in('Title', $tag);
        $query = $this->db->get('Tag', 1);
        $result = $query->result();
        // Return ID of Tag
        //return $result[0]->TagID;
        print_r($result);
}
  • 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-23T04:13:09+00:00Added an answer on May 23, 2026 at 4:13 am

    Its because of this code right here:

                array_push($currentTags, strtolower($tag));
                // Get ID of tags that are existing
                foreach ($currentTags as $tagname) 
                {
                    $id = $this->Bookmark_model->get_tag_id($tagname);
                    echo $id;
                }
    

    Remove the foreach and it will no longer print the first array twice.

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

Sidebar

Related Questions

I'm trying to get HTML5's audio tag to work in Chrome. The following code
I need to get this Jquery box to appear on page load. Right now
I have the following page: mysite.com/news/index.php?tag=tag&name=name&id=id I want to rewrite this so that it
In my index file I get data from the database using this function (which
I seem to get something fundamentally wrong. I have this HTML <div id=thumbnails> <a
I was wondering if something like this, is safe in Zend: $db = Zend_Registry::get('db');
If you have the following table structure: item: id, content ect item_tags: item_id, tag_id
Here I have a simple join query. If first two queries get results, the
Can I get some help with this query. I will explain in details. To
I've been trying to get the following method cleaned up using more sensible and

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.