passing an array to a view in CodeIgniterphp - How do I fix this illegal offset type errorHow should I choose an authentication library for CodeIgniter?PHP: Delete an element from an arrayFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Get the first element of an arrayHow to Sort Multi-dimensional Array by Value?Remove empty array elementsPHP array delete by value (not key)Combining and returning arrays from Model to Controller - CodeIgniterMysql, the last decimal zero disappears in Float data type for product pricesajax dependent dropdown codeigniter

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

There is only s̶i̶x̶t̶y one place he can be

Irreducibility of a simple polynomial

Why Were Madagascar and New Zealand Discovered So Late?

Generic lambda vs generic function give different behaviour

Products and sum of cubes in Fibonacci

What to do with wrong results in talks?

At which point does a character regain all their Hit Dice?

Hide Select Output from T-SQL

How does a character multiclassing into warlock get a focus?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

Can a monster with multiattack use this ability if they are missing a limb?

when is out of tune ok?

What would happen if the UK refused to take part in EU Parliamentary elections?

Is exact Kanji stroke length important?

Is a roofing delivery truck likely to crack my driveway slab?

Mapping a list into a phase plot

Everything Bob says is false. How does he get people to trust him?

The plural of 'stomach"

What is the intuitive meaning of having a linear relationship between the logs of two variables?

What would be the benefits of having both a state and local currencies?

Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads

Why "be dealt cards" rather than "be dealing cards"?

Finding all intervals that match predicate in vector



passing an array to a view in CodeIgniter


php - How do I fix this illegal offset type errorHow should I choose an authentication library for CodeIgniter?PHP: Delete an element from an arrayFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)Get the first element of an arrayHow to Sort Multi-dimensional Array by Value?Remove empty array elementsPHP array delete by value (not key)Combining and returning arrays from Model to Controller - CodeIgniterMysql, the last decimal zero disappears in Float data type for product pricesajax dependent dropdown codeigniter













1















I have a model which looks like this



function find($where)

$arr = $this->db->get_where($this->table,$where)->result_array();

foreach ($arr as $value)

$prod_id = $value["id"];

$value['image']=$this->db->get_where("photos",['prod_id'=>$prod_id])->result_array();



return $value;




It gives me this array



Array(
[id] => 70
[name] => rrwerwer
[count] => 234
[price] => 234.00
[description] =>
[user_id] => 20
[image] => Array
(
[0] => Array
(
[id] => 88
[prod_id] => 70
[link] => 1_HP8l7LMMt7Sh5UoO1T-yLQ37.png
)))


In my Controller I have try to load a view and pass my array to it



$data = $this->productmodel->find(["user_id =" => $this->session->user["id"]]);
$this->load->view('myproduct', ["products" => $data]);


And in the view run a foreach on the array and print things



<?php foreach($products as $prod){ ?>

<div class="productDiv">

<div class="productName">

<span class="productNameSpan">
<?=$prod["name"]?>
</span>

</div>

<div class="productPrice">

<label class="productPriceLabel">Գին: <?=$prod["price"]." դրամ"?></label>

</div>

<div class="productCount">

<label class="productCountLabel">Քանակ: <?=$prod["count"]."X" ?></label>

</div>

<div class="productDescribtion">

<label class="productDescribtipnLabel">Նկարագիր: <?=$prod["description"] ?></label>

</div>

<div class="seeMoreDiv">

<button class="seeMoreButton btn btn-success">

ՏԵՍՆԵԼ ԱՎԵԼԻՆ

</button>

</div>
</div>


It gives me errors 'illegal offset name,price etc...'
How can I fix this problem?
I need to print the information of the product and show images of it










share|improve this question






















  • $prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

    – Sayed Mohd Ali
    Mar 8 at 9:42












  • Possible duplicate of php - How do I fix this illegal offset type error

    – Sayed Mohd Ali
    Mar 8 at 9:43











  • i think it's looking like object array , try var_dump or print_r

    – Steve Good Job
    Mar 8 at 10:22















1















I have a model which looks like this



function find($where)

$arr = $this->db->get_where($this->table,$where)->result_array();

foreach ($arr as $value)

$prod_id = $value["id"];

$value['image']=$this->db->get_where("photos",['prod_id'=>$prod_id])->result_array();



return $value;




It gives me this array



Array(
[id] => 70
[name] => rrwerwer
[count] => 234
[price] => 234.00
[description] =>
[user_id] => 20
[image] => Array
(
[0] => Array
(
[id] => 88
[prod_id] => 70
[link] => 1_HP8l7LMMt7Sh5UoO1T-yLQ37.png
)))


In my Controller I have try to load a view and pass my array to it



$data = $this->productmodel->find(["user_id =" => $this->session->user["id"]]);
$this->load->view('myproduct', ["products" => $data]);


And in the view run a foreach on the array and print things



<?php foreach($products as $prod){ ?>

<div class="productDiv">

<div class="productName">

<span class="productNameSpan">
<?=$prod["name"]?>
</span>

</div>

<div class="productPrice">

<label class="productPriceLabel">Գին: <?=$prod["price"]." դրամ"?></label>

</div>

<div class="productCount">

<label class="productCountLabel">Քանակ: <?=$prod["count"]."X" ?></label>

</div>

<div class="productDescribtion">

<label class="productDescribtipnLabel">Նկարագիր: <?=$prod["description"] ?></label>

</div>

<div class="seeMoreDiv">

<button class="seeMoreButton btn btn-success">

ՏԵՍՆԵԼ ԱՎԵԼԻՆ

</button>

</div>
</div>


It gives me errors 'illegal offset name,price etc...'
How can I fix this problem?
I need to print the information of the product and show images of it










share|improve this question






















  • $prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

    – Sayed Mohd Ali
    Mar 8 at 9:42












  • Possible duplicate of php - How do I fix this illegal offset type error

    – Sayed Mohd Ali
    Mar 8 at 9:43











  • i think it's looking like object array , try var_dump or print_r

    – Steve Good Job
    Mar 8 at 10:22













1












1








1








I have a model which looks like this



function find($where)

$arr = $this->db->get_where($this->table,$where)->result_array();

foreach ($arr as $value)

$prod_id = $value["id"];

$value['image']=$this->db->get_where("photos",['prod_id'=>$prod_id])->result_array();



return $value;




It gives me this array



Array(
[id] => 70
[name] => rrwerwer
[count] => 234
[price] => 234.00
[description] =>
[user_id] => 20
[image] => Array
(
[0] => Array
(
[id] => 88
[prod_id] => 70
[link] => 1_HP8l7LMMt7Sh5UoO1T-yLQ37.png
)))


In my Controller I have try to load a view and pass my array to it



$data = $this->productmodel->find(["user_id =" => $this->session->user["id"]]);
$this->load->view('myproduct', ["products" => $data]);


And in the view run a foreach on the array and print things



<?php foreach($products as $prod){ ?>

<div class="productDiv">

<div class="productName">

<span class="productNameSpan">
<?=$prod["name"]?>
</span>

</div>

<div class="productPrice">

<label class="productPriceLabel">Գին: <?=$prod["price"]." դրամ"?></label>

</div>

<div class="productCount">

<label class="productCountLabel">Քանակ: <?=$prod["count"]."X" ?></label>

</div>

<div class="productDescribtion">

<label class="productDescribtipnLabel">Նկարագիր: <?=$prod["description"] ?></label>

</div>

<div class="seeMoreDiv">

<button class="seeMoreButton btn btn-success">

ՏԵՍՆԵԼ ԱՎԵԼԻՆ

</button>

</div>
</div>


It gives me errors 'illegal offset name,price etc...'
How can I fix this problem?
I need to print the information of the product and show images of it










share|improve this question














I have a model which looks like this



function find($where)

$arr = $this->db->get_where($this->table,$where)->result_array();

foreach ($arr as $value)

$prod_id = $value["id"];

$value['image']=$this->db->get_where("photos",['prod_id'=>$prod_id])->result_array();



return $value;




It gives me this array



Array(
[id] => 70
[name] => rrwerwer
[count] => 234
[price] => 234.00
[description] =>
[user_id] => 20
[image] => Array
(
[0] => Array
(
[id] => 88
[prod_id] => 70
[link] => 1_HP8l7LMMt7Sh5UoO1T-yLQ37.png
)))


In my Controller I have try to load a view and pass my array to it



$data = $this->productmodel->find(["user_id =" => $this->session->user["id"]]);
$this->load->view('myproduct', ["products" => $data]);


And in the view run a foreach on the array and print things



<?php foreach($products as $prod){ ?>

<div class="productDiv">

<div class="productName">

<span class="productNameSpan">
<?=$prod["name"]?>
</span>

</div>

<div class="productPrice">

<label class="productPriceLabel">Գին: <?=$prod["price"]." դրամ"?></label>

</div>

<div class="productCount">

<label class="productCountLabel">Քանակ: <?=$prod["count"]."X" ?></label>

</div>

<div class="productDescribtion">

<label class="productDescribtipnLabel">Նկարագիր: <?=$prod["description"] ?></label>

</div>

<div class="seeMoreDiv">

<button class="seeMoreButton btn btn-success">

ՏԵՍՆԵԼ ԱՎԵԼԻՆ

</button>

</div>
</div>


It gives me errors 'illegal offset name,price etc...'
How can I fix this problem?
I need to print the information of the product and show images of it







php codeigniter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 9:36









Grigory VolkovGrigory Volkov

61




61












  • $prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

    – Sayed Mohd Ali
    Mar 8 at 9:42












  • Possible duplicate of php - How do I fix this illegal offset type error

    – Sayed Mohd Ali
    Mar 8 at 9:43











  • i think it's looking like object array , try var_dump or print_r

    – Steve Good Job
    Mar 8 at 10:22

















  • $prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

    – Sayed Mohd Ali
    Mar 8 at 9:42












  • Possible duplicate of php - How do I fix this illegal offset type error

    – Sayed Mohd Ali
    Mar 8 at 9:43











  • i think it's looking like object array , try var_dump or print_r

    – Steve Good Job
    Mar 8 at 10:22
















$prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

– Sayed Mohd Ali
Mar 8 at 9:42






$prod id not an array that is why you are getting illegal offset error please echo $prod;die; or print_r($prod);die; to check it is an array or not

– Sayed Mohd Ali
Mar 8 at 9:42














Possible duplicate of php - How do I fix this illegal offset type error

– Sayed Mohd Ali
Mar 8 at 9:43





Possible duplicate of php - How do I fix this illegal offset type error

– Sayed Mohd Ali
Mar 8 at 9:43













i think it's looking like object array , try var_dump or print_r

– Steve Good Job
Mar 8 at 10:22





i think it's looking like object array , try var_dump or print_r

– Steve Good Job
Mar 8 at 10:22












1 Answer
1






active

oldest

votes


















2














Don't use foreach() and try like this



echo $products["price"];


Only use foreach() on $products['image']






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060394%2fpassing-an-array-to-a-view-in-codeigniter%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Don't use foreach() and try like this



    echo $products["price"];


    Only use foreach() on $products['image']






    share|improve this answer



























      2














      Don't use foreach() and try like this



      echo $products["price"];


      Only use foreach() on $products['image']






      share|improve this answer

























        2












        2








        2







        Don't use foreach() and try like this



        echo $products["price"];


        Only use foreach() on $products['image']






        share|improve this answer













        Don't use foreach() and try like this



        echo $products["price"];


        Only use foreach() on $products['image']







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 9:40









        Danish AliDanish Ali

        1,70531021




        1,70531021





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060394%2fpassing-an-array-to-a-view-in-codeigniter%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived