How to Set a Limit on Echo?












0














Needed help here on how to set limit for my table. I just want the first and single value but i couldnt find solution on this.



As i have inserted dates and times in my table. So it looks like this, it has repeated values for both Date and Time.



Date : 19-11-1819-11-18



Time : 05:21:0705:32:10



I just want single value for both Date and Time. Here is my codes.



Date :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_date'];
}
?>


Time :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_time'];
}
?>


Appreciate for your help!










share|improve this question
























  • Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
    – Magnus Eriksson
    Nov 19 '18 at 18:51












  • It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
    – Stella
    Nov 19 '18 at 18:57










  • Im sorry Im very new to php. ;(
    – Stella
    Nov 19 '18 at 18:58










  • Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
    – Magnus Eriksson
    Nov 19 '18 at 19:00












  • As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
    – uom-pgregorio
    Nov 19 '18 at 19:07
















0














Needed help here on how to set limit for my table. I just want the first and single value but i couldnt find solution on this.



As i have inserted dates and times in my table. So it looks like this, it has repeated values for both Date and Time.



Date : 19-11-1819-11-18



Time : 05:21:0705:32:10



I just want single value for both Date and Time. Here is my codes.



Date :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_date'];
}
?>


Time :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_time'];
}
?>


Appreciate for your help!










share|improve this question
























  • Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
    – Magnus Eriksson
    Nov 19 '18 at 18:51












  • It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
    – Stella
    Nov 19 '18 at 18:57










  • Im sorry Im very new to php. ;(
    – Stella
    Nov 19 '18 at 18:58










  • Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
    – Magnus Eriksson
    Nov 19 '18 at 19:00












  • As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
    – uom-pgregorio
    Nov 19 '18 at 19:07














0












0








0







Needed help here on how to set limit for my table. I just want the first and single value but i couldnt find solution on this.



As i have inserted dates and times in my table. So it looks like this, it has repeated values for both Date and Time.



Date : 19-11-1819-11-18



Time : 05:21:0705:32:10



I just want single value for both Date and Time. Here is my codes.



Date :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_date'];
}
?>


Time :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_time'];
}
?>


Appreciate for your help!










share|improve this question















Needed help here on how to set limit for my table. I just want the first and single value but i couldnt find solution on this.



As i have inserted dates and times in my table. So it looks like this, it has repeated values for both Date and Time.



Date : 19-11-1819-11-18



Time : 05:21:0705:32:10



I just want single value for both Date and Time. Here is my codes.



Date :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_date'];
}
?>


Time :



<?php
mysqli_data_seek($results, 0);// second instance
while($row = mysqli_fetch_array($results)) {
echo $row['check_time'];
}
?>


Appreciate for your help!







php echo limit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 18:47









TylerH

15.4k105067




15.4k105067










asked Nov 19 '18 at 18:43









StellaStella

1




1












  • Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
    – Magnus Eriksson
    Nov 19 '18 at 18:51












  • It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
    – Stella
    Nov 19 '18 at 18:57










  • Im sorry Im very new to php. ;(
    – Stella
    Nov 19 '18 at 18:58










  • Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
    – Magnus Eriksson
    Nov 19 '18 at 19:00












  • As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
    – uom-pgregorio
    Nov 19 '18 at 19:07


















  • Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
    – Magnus Eriksson
    Nov 19 '18 at 18:51












  • It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
    – Stella
    Nov 19 '18 at 18:57










  • Im sorry Im very new to php. ;(
    – Stella
    Nov 19 '18 at 18:58










  • Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
    – Magnus Eriksson
    Nov 19 '18 at 19:00












  • As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
    – uom-pgregorio
    Nov 19 '18 at 19:07
















Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
– Magnus Eriksson
Nov 19 '18 at 18:51






Is the value in your database actually 19-11-1819-11-18? Why is it doubled? Also, where is your query? Why are you not fetching both time and date in one go? Are you storing the date and time as strings? Why not use date and time types? You should also let us know what actually happens when you run your code. What is the actual issue with it?
– Magnus Eriksson
Nov 19 '18 at 18:51














It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
– Stella
Nov 19 '18 at 18:57




It supposed to be only 19-11-18, but it is because i have two columns with the same date, and i could only fetch both values, which that is why it got doubled. Still looking for solution on how to limit the value using echo. I just wanted the first single date.
– Stella
Nov 19 '18 at 18:57












Im sorry Im very new to php. ;(
– Stella
Nov 19 '18 at 18:58




Im sorry Im very new to php. ;(
– Stella
Nov 19 '18 at 18:58












Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
– Magnus Eriksson
Nov 19 '18 at 19:00






Just select the columns you need and echo those columns? Not sure what the actual issue is. Or do you mean that you have two rows with the same date? That's a big difference. If you just want the first, just add LIMIT 1 at the end of your query. The question is still a bit unclear.
– Magnus Eriksson
Nov 19 '18 at 19:00














As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
– uom-pgregorio
Nov 19 '18 at 19:07




As @MagnusEriksson mentioned, it seems like your problem is on the query not PHP. You could do the LIMIT 1 as he suggested or you could do something like SELECT DISTINCT check_time FROM check_table.
– uom-pgregorio
Nov 19 '18 at 19:07












2 Answers
2






active

oldest

votes


















1














Use substr() to only show the first 'n' of your output



echo substr($row['check_date'],0,8);


but really, as Magnus says, you need to work out why your database is storing the date/time twice and consider moving to using actual datetime fields instead.






share|improve this answer

















  • 1




    This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
    – uom-pgregorio
    Nov 19 '18 at 19:09





















0














There are several ways of doing this, but the simplest with just the lines of code you have is to not use a loop - if you want 1 value then just fetch 1 row of data...



mysqli_data_seek($results, 0);// second instance
$row = mysqli_fetch_array($results);
echo $row['check_date'];


One thing I would suggest is that it may be easier also to just fetch the data in one place. Now you've fetched the data into $row you can latter on just echo out the data already retrieved...



echo $row['check_time'];


although you may be safer to read it into something with a more unique name so that you don't re-use the $row and loose the values...



mysqli_data_seek($results, 0);// second instance
$checkData = mysqli_fetch_array($results);
echo $checkData['check_date'];





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%2f53380827%2fhow-to-set-a-limit-on-echo%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Use substr() to only show the first 'n' of your output



    echo substr($row['check_date'],0,8);


    but really, as Magnus says, you need to work out why your database is storing the date/time twice and consider moving to using actual datetime fields instead.






    share|improve this answer

















    • 1




      This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
      – uom-pgregorio
      Nov 19 '18 at 19:09


















    1














    Use substr() to only show the first 'n' of your output



    echo substr($row['check_date'],0,8);


    but really, as Magnus says, you need to work out why your database is storing the date/time twice and consider moving to using actual datetime fields instead.






    share|improve this answer

















    • 1




      This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
      – uom-pgregorio
      Nov 19 '18 at 19:09
















    1












    1








    1






    Use substr() to only show the first 'n' of your output



    echo substr($row['check_date'],0,8);


    but really, as Magnus says, you need to work out why your database is storing the date/time twice and consider moving to using actual datetime fields instead.






    share|improve this answer












    Use substr() to only show the first 'n' of your output



    echo substr($row['check_date'],0,8);


    but really, as Magnus says, you need to work out why your database is storing the date/time twice and consider moving to using actual datetime fields instead.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 '18 at 19:00









    Mark Mark

    364




    364








    • 1




      This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
      – uom-pgregorio
      Nov 19 '18 at 19:09
















    • 1




      This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
      – uom-pgregorio
      Nov 19 '18 at 19:09










    1




    1




    This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
    – uom-pgregorio
    Nov 19 '18 at 19:09






    This won't fix anything. Currently the echo statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Using substr doesn't do anything here.
    – uom-pgregorio
    Nov 19 '18 at 19:09















    0














    There are several ways of doing this, but the simplest with just the lines of code you have is to not use a loop - if you want 1 value then just fetch 1 row of data...



    mysqli_data_seek($results, 0);// second instance
    $row = mysqli_fetch_array($results);
    echo $row['check_date'];


    One thing I would suggest is that it may be easier also to just fetch the data in one place. Now you've fetched the data into $row you can latter on just echo out the data already retrieved...



    echo $row['check_time'];


    although you may be safer to read it into something with a more unique name so that you don't re-use the $row and loose the values...



    mysqli_data_seek($results, 0);// second instance
    $checkData = mysqli_fetch_array($results);
    echo $checkData['check_date'];





    share|improve this answer


























      0














      There are several ways of doing this, but the simplest with just the lines of code you have is to not use a loop - if you want 1 value then just fetch 1 row of data...



      mysqli_data_seek($results, 0);// second instance
      $row = mysqli_fetch_array($results);
      echo $row['check_date'];


      One thing I would suggest is that it may be easier also to just fetch the data in one place. Now you've fetched the data into $row you can latter on just echo out the data already retrieved...



      echo $row['check_time'];


      although you may be safer to read it into something with a more unique name so that you don't re-use the $row and loose the values...



      mysqli_data_seek($results, 0);// second instance
      $checkData = mysqli_fetch_array($results);
      echo $checkData['check_date'];





      share|improve this answer
























        0












        0








        0






        There are several ways of doing this, but the simplest with just the lines of code you have is to not use a loop - if you want 1 value then just fetch 1 row of data...



        mysqli_data_seek($results, 0);// second instance
        $row = mysqli_fetch_array($results);
        echo $row['check_date'];


        One thing I would suggest is that it may be easier also to just fetch the data in one place. Now you've fetched the data into $row you can latter on just echo out the data already retrieved...



        echo $row['check_time'];


        although you may be safer to read it into something with a more unique name so that you don't re-use the $row and loose the values...



        mysqli_data_seek($results, 0);// second instance
        $checkData = mysqli_fetch_array($results);
        echo $checkData['check_date'];





        share|improve this answer












        There are several ways of doing this, but the simplest with just the lines of code you have is to not use a loop - if you want 1 value then just fetch 1 row of data...



        mysqli_data_seek($results, 0);// second instance
        $row = mysqli_fetch_array($results);
        echo $row['check_date'];


        One thing I would suggest is that it may be easier also to just fetch the data in one place. Now you've fetched the data into $row you can latter on just echo out the data already retrieved...



        echo $row['check_time'];


        although you may be safer to read it into something with a more unique name so that you don't re-use the $row and loose the values...



        mysqli_data_seek($results, 0);// second instance
        $checkData = mysqli_fetch_array($results);
        echo $checkData['check_date'];






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 20:06









        Nigel RenNigel Ren

        25.5k61832




        25.5k61832






























            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%2f53380827%2fhow-to-set-a-limit-on-echo%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

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith