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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:39:54+00:00 2026-06-13T09:39:54+00:00

I’m using the Cart class in Codeigniter. What I want to do should (hopefully!)

  • 0

I’m using the Cart class in Codeigniter. What I want to do should (hopefully!) be simple… but i’m struggling.

On the product page, I have a button to ‘add to cart’. What I want to happen is that when the item is already in the cart, the button changes to ‘remove from cart’.

<? //if(**not in cart**) { ?>
    <a href="<?=base_url()?>jobs/addjob/<?=$row->id?>">Add to cart</a>
<? } else { ?>
    <a href="<?=base_url()?>jobs/removejob/<? /**cart 'rowid'**/ echo $rowid?>">Remove from cart</a>
<? } ?>

How can I query the cart to see if that item is in there or not and get the ‘rowid’ so I can use that for a remove function?

Many thanks!

  • 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-13T09:39:55+00:00Added an answer on June 13, 2026 at 9:39 am

    I had a similar problem – I got round it by extending the CI_Cart library with 2 new functions – in_cart() and all_item_count().

    <?php
    class MY_Cart extends CI_Cart {
    
        function __construct() 
            {
                parent::__construct();
                $this->product_name_rules = '\d\D';
            }
    
    /*
     * Returns data for products in cart
     * 
     * @param integer $product_id used to fetch only the quantity of a specific product
     * @return array|integer $in_cart an array in the form (id => quantity, ....) OR quantity if $product_id is set
     */
    public function in_cart($product_id = null) {
        if ($this->total_items() > 0)
        {
            $in_cart = array();
            // Fetch data for all products in cart
            foreach ($this->contents() AS $item)
            {
                $in_cart[$item['id']] = $item['qty'];
            }
            if ($product_id)
            {
                if (array_key_exists($product_id, $in_cart))
                {
                    return $in_cart[$product_id];
                }
                return null;
            }
            else
            {
                return $in_cart;
            }
        }
        return null;    
    }
    
    public function all_item_count()
    {
        $total = 0;
    
        if ($this->total_items() > 0)
        {
            foreach ($this->contents() AS $item)
            {
                $total = $item['qty'] + $total;
            }
        }
    
        return $total;
    }
     }
     /* End of file: MY_Cart.php */
     /* Location: ./application/libraries/MY_Cart.php */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I

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.