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

  • Home
  • SEARCH
  • 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 8472765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:09:59+00:00 2026-06-10T17:09:59+00:00

i am using codeigniter library, and am stuck in a matter. first here’s my

  • 0

i am using codeigniter library, and am stuck in a matter. first here’s my array

Array (
    [0] => Array (
        [product_name] => some data
        [product_slug] => some data
        [price] => some Data...
        [sell_price] => 2000.00

    )

    [1] => Array (
        [product_name] => some data
        [product_slug] => some data
        [price] => some Data...
        [sell_price] => 2000.00
    )
)

now here’s my code in controller:

$this->load->model('product_model');
$data['product']=$this->product_model->get_product();
$this->load->view('show_product',$data);

and heres my model codes

function get_product()
{
  return $this->db->query("SELECT * FROM dt_product")->result_array();
}

and ultimately my view code

<div class="featured_right_gallery_bellow">
                    <ul class="product_list">
                                        <?php foreach($product as $product)
                                        {?>
                    <li>
                    <div class="pro_name"><?php echo $product['product_name'];?></div>
                    </li>
                    <?php
                    }?>
                    </ul>
</div>

now my question is that, i want to jst show the first 20 letters of the product_name….but here the full name is being shown…

i know i can write a mysql code like SELECT LEFT(product_name,20),sell_price,price FROM dt_product… but i dont want to do that, because the table contains nearly 20 attributes, and i have to change the query multiple times…. all i want is to someone point me out to the solution of how to display the first 20 letter of the product_name using the offset concept,

i tried echoing $product[‘product_name’][20], but withing foreach loop, its throwing an error of undefined index..

  • 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-10T17:10:01+00:00Added an answer on June 10, 2026 at 5:10 pm

    Try this:

    <div class="pro_name"><?php echo substr($product['product_name'], 0, 20);?></div>
    

    Read up on function substr() here: http://php.net/manual/en/function.substr.php

    Edit:

    If you want to do the edit directly in your array (which I don’t think is necessary):

    Assuming $array is the array:

    Array (
        [0] => Array (
            [product_name] => some data
            [product_slug] => some data
            [price] => some Data...
            [sell_price] => 2000.00
    
        )
    
        [1] => Array (
            [product_name] => some data
            [product_slug] => some data
            [price] => some Data...
            [sell_price] => 2000.00
        )
    )
    

    Then do this:

    // Iterating through each of the elements of the array.
    // $productArray gets loaded as each inner array value.
    foreach ($array as $key => $productArray) {
        // The value of $array[$key] is the current inner array.
        // The substr() just gets the value of the product_name key and returns the first 20 characters.
        // To load the modified value, set $array[$key]['product_name'] to the modified value.
        $array[$key]['product_name'] = substr($productArray['product_name'], 0, 20);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first question on codeigniter. I have integrated paypal in codeigniter using paypal library.
Background: Using CodeIgniter with this MongoDB library . This is my first go-round with
I have some codeigniter driven sub-domains and using native codeigniter session library. There is
I am using Codeigniter message library. In my controller I have the following code
I'm using Codeigniter's image manipulation library to re-size an uploaded image to three sizes,
I am using cezPDF library in CodeIgniter 2 But it seems it can't print
I'm using Adam Griffiths's Authentication Library for CodeIgniter and I'm tweaking the usermodel. I
I am using CodeIgniter to upload some files through a form. I know how
I am developing a website using Codeigniter and MongoDB (Alex Bilbie library). Currently there
I'm sending out an email using CodeIgniter 's built in library. All I'm trying

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.