PHP mysql session array












1














I have a little question.



I have few stored values in session Array. These values are ID's of products.
After that i want to display products from my database, but this is not working propertly for me.
Can someone help me a little? :) (I am still learning :) )



<?php
include 'includes/dbconnect.php';
$orderid = $_SESSION['order'];
foreach ($orderid as $value) {
$sql="SELECT * FROM product WHERE productID LIKE '%$value%'";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
echo '<tr>';
echo '<td>'.$row["tag"].'</td>';
echo '<td>'.$row["price"].',- Kč</td>';
echo '<td><a href="product.php?id='.$row["productID"].'"><img src="images/'.$row["tag"].'.jpg" width=70"></a></td>';
echo '<td>1</td>' ;
echo '<td><a href="#" class="btn btn-danger btn-lg">X</a></td>';
}
}
?>


var_dump($orderid); shows:



array(1) {
["order"]=> array(10) {
[0]=> string(2) "44"
[1]=> string(2) "46"
[2]=> string(2) "44"
[3]=> string(2) "54"
[4]=> string(1) "1"
[5]=> string(2) "44"
[6]=> string(1) "1"
[7]=> string(2) "44"
[8]=> string(2) "47"
[9]=> string(2) "74"
}
}









share|improve this question




















  • 1




    add the error message(s) you get.We cannot debug this for you without more information on what went wrong
    – Akintunde-Rotimi
    Nov 21 '18 at 15:58






  • 3




    i don't see session_start()
    – suresh bambhaniya
    Nov 21 '18 at 15:59






  • 1




    In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
    – Studocwho
    Nov 21 '18 at 16:10








  • 1




    OHHH thanks Studocwho :) thats it!! :) thanks alot :)
    – Pe Tr
    Nov 21 '18 at 16:12






  • 1




    why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
    – Fanie Void
    Nov 21 '18 at 16:16
















1














I have a little question.



I have few stored values in session Array. These values are ID's of products.
After that i want to display products from my database, but this is not working propertly for me.
Can someone help me a little? :) (I am still learning :) )



<?php
include 'includes/dbconnect.php';
$orderid = $_SESSION['order'];
foreach ($orderid as $value) {
$sql="SELECT * FROM product WHERE productID LIKE '%$value%'";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
echo '<tr>';
echo '<td>'.$row["tag"].'</td>';
echo '<td>'.$row["price"].',- Kč</td>';
echo '<td><a href="product.php?id='.$row["productID"].'"><img src="images/'.$row["tag"].'.jpg" width=70"></a></td>';
echo '<td>1</td>' ;
echo '<td><a href="#" class="btn btn-danger btn-lg">X</a></td>';
}
}
?>


var_dump($orderid); shows:



array(1) {
["order"]=> array(10) {
[0]=> string(2) "44"
[1]=> string(2) "46"
[2]=> string(2) "44"
[3]=> string(2) "54"
[4]=> string(1) "1"
[5]=> string(2) "44"
[6]=> string(1) "1"
[7]=> string(2) "44"
[8]=> string(2) "47"
[9]=> string(2) "74"
}
}









share|improve this question




















  • 1




    add the error message(s) you get.We cannot debug this for you without more information on what went wrong
    – Akintunde-Rotimi
    Nov 21 '18 at 15:58






  • 3




    i don't see session_start()
    – suresh bambhaniya
    Nov 21 '18 at 15:59






  • 1




    In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
    – Studocwho
    Nov 21 '18 at 16:10








  • 1




    OHHH thanks Studocwho :) thats it!! :) thanks alot :)
    – Pe Tr
    Nov 21 '18 at 16:12






  • 1




    why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
    – Fanie Void
    Nov 21 '18 at 16:16














1












1








1







I have a little question.



I have few stored values in session Array. These values are ID's of products.
After that i want to display products from my database, but this is not working propertly for me.
Can someone help me a little? :) (I am still learning :) )



<?php
include 'includes/dbconnect.php';
$orderid = $_SESSION['order'];
foreach ($orderid as $value) {
$sql="SELECT * FROM product WHERE productID LIKE '%$value%'";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
echo '<tr>';
echo '<td>'.$row["tag"].'</td>';
echo '<td>'.$row["price"].',- Kč</td>';
echo '<td><a href="product.php?id='.$row["productID"].'"><img src="images/'.$row["tag"].'.jpg" width=70"></a></td>';
echo '<td>1</td>' ;
echo '<td><a href="#" class="btn btn-danger btn-lg">X</a></td>';
}
}
?>


var_dump($orderid); shows:



array(1) {
["order"]=> array(10) {
[0]=> string(2) "44"
[1]=> string(2) "46"
[2]=> string(2) "44"
[3]=> string(2) "54"
[4]=> string(1) "1"
[5]=> string(2) "44"
[6]=> string(1) "1"
[7]=> string(2) "44"
[8]=> string(2) "47"
[9]=> string(2) "74"
}
}









share|improve this question















I have a little question.



I have few stored values in session Array. These values are ID's of products.
After that i want to display products from my database, but this is not working propertly for me.
Can someone help me a little? :) (I am still learning :) )



<?php
include 'includes/dbconnect.php';
$orderid = $_SESSION['order'];
foreach ($orderid as $value) {
$sql="SELECT * FROM product WHERE productID LIKE '%$value%'";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
echo '<tr>';
echo '<td>'.$row["tag"].'</td>';
echo '<td>'.$row["price"].',- Kč</td>';
echo '<td><a href="product.php?id='.$row["productID"].'"><img src="images/'.$row["tag"].'.jpg" width=70"></a></td>';
echo '<td>1</td>' ;
echo '<td><a href="#" class="btn btn-danger btn-lg">X</a></td>';
}
}
?>


var_dump($orderid); shows:



array(1) {
["order"]=> array(10) {
[0]=> string(2) "44"
[1]=> string(2) "46"
[2]=> string(2) "44"
[3]=> string(2) "54"
[4]=> string(1) "1"
[5]=> string(2) "44"
[6]=> string(1) "1"
[7]=> string(2) "44"
[8]=> string(2) "47"
[9]=> string(2) "74"
}
}






php mysql session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 16:45









Fanie Void

1619




1619










asked Nov 21 '18 at 15:55









Pe TrPe Tr

62




62








  • 1




    add the error message(s) you get.We cannot debug this for you without more information on what went wrong
    – Akintunde-Rotimi
    Nov 21 '18 at 15:58






  • 3




    i don't see session_start()
    – suresh bambhaniya
    Nov 21 '18 at 15:59






  • 1




    In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
    – Studocwho
    Nov 21 '18 at 16:10








  • 1




    OHHH thanks Studocwho :) thats it!! :) thanks alot :)
    – Pe Tr
    Nov 21 '18 at 16:12






  • 1




    why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
    – Fanie Void
    Nov 21 '18 at 16:16














  • 1




    add the error message(s) you get.We cannot debug this for you without more information on what went wrong
    – Akintunde-Rotimi
    Nov 21 '18 at 15:58






  • 3




    i don't see session_start()
    – suresh bambhaniya
    Nov 21 '18 at 15:59






  • 1




    In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
    – Studocwho
    Nov 21 '18 at 16:10








  • 1




    OHHH thanks Studocwho :) thats it!! :) thanks alot :)
    – Pe Tr
    Nov 21 '18 at 16:12






  • 1




    why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
    – Fanie Void
    Nov 21 '18 at 16:16








1




1




add the error message(s) you get.We cannot debug this for you without more information on what went wrong
– Akintunde-Rotimi
Nov 21 '18 at 15:58




add the error message(s) you get.We cannot debug this for you without more information on what went wrong
– Akintunde-Rotimi
Nov 21 '18 at 15:58




3




3




i don't see session_start()
– suresh bambhaniya
Nov 21 '18 at 15:59




i don't see session_start()
– suresh bambhaniya
Nov 21 '18 at 15:59




1




1




In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
– Studocwho
Nov 21 '18 at 16:10






In $sql query instead of using LIKE '%$value%'"; try this: LIKE '". $value ."'";
– Studocwho
Nov 21 '18 at 16:10






1




1




OHHH thanks Studocwho :) thats it!! :) thanks alot :)
– Pe Tr
Nov 21 '18 at 16:12




OHHH thanks Studocwho :) thats it!! :) thanks alot :)
– Pe Tr
Nov 21 '18 at 16:12




1




1




why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
– Fanie Void
Nov 21 '18 at 16:16




why searching complicated when it's simple ? x) @Studocwho then you just have to make it an answer
– Fanie Void
Nov 21 '18 at 16:16












1 Answer
1






active

oldest

votes


















1














Just for the purposes of SO, I'll make my comment as an answer:



In the $sql query instead of using LIKE '%$value%'"; use this: LIKE '". $value ."'";



This ensures that we actually get the value of the variable.






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%2f53415890%2fphp-mysql-session-array%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









    1














    Just for the purposes of SO, I'll make my comment as an answer:



    In the $sql query instead of using LIKE '%$value%'"; use this: LIKE '". $value ."'";



    This ensures that we actually get the value of the variable.






    share|improve this answer


























      1














      Just for the purposes of SO, I'll make my comment as an answer:



      In the $sql query instead of using LIKE '%$value%'"; use this: LIKE '". $value ."'";



      This ensures that we actually get the value of the variable.






      share|improve this answer
























        1












        1








        1






        Just for the purposes of SO, I'll make my comment as an answer:



        In the $sql query instead of using LIKE '%$value%'"; use this: LIKE '". $value ."'";



        This ensures that we actually get the value of the variable.






        share|improve this answer












        Just for the purposes of SO, I'll make my comment as an answer:



        In the $sql query instead of using LIKE '%$value%'"; use this: LIKE '". $value ."'";



        This ensures that we actually get the value of the variable.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 16:21









        StudocwhoStudocwho

        1,04811120




        1,04811120






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53415890%2fphp-mysql-session-array%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

            Wiesbaden

            Marschland

            Dieringhausen