How to Set a Limit on Echo?
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
add a comment |
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
Is the value in your database actually19-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 addLIMIT 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 theLIMIT 1
as he suggested or you could do something likeSELECT DISTINCT check_time FROM check_table
.
– uom-pgregorio
Nov 19 '18 at 19:07
add a comment |
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
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
php echo limit
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 actually19-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 addLIMIT 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 theLIMIT 1
as he suggested or you could do something likeSELECT DISTINCT check_time FROM check_table
.
– uom-pgregorio
Nov 19 '18 at 19:07
add a comment |
Is the value in your database actually19-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 addLIMIT 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 theLIMIT 1
as he suggested or you could do something likeSELECT 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
add a comment |
2 Answers
2
active
oldest
votes
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.
1
This won't fix anything. Currently theecho
statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Usingsubstr
doesn't do anything here.
– uom-pgregorio
Nov 19 '18 at 19:09
add a comment |
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'];
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
1
This won't fix anything. Currently theecho
statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Usingsubstr
doesn't do anything here.
– uom-pgregorio
Nov 19 '18 at 19:09
add a comment |
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.
1
This won't fix anything. Currently theecho
statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Usingsubstr
doesn't do anything here.
– uom-pgregorio
Nov 19 '18 at 19:09
add a comment |
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.
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.
answered Nov 19 '18 at 19:00
Mark Mark
364
364
1
This won't fix anything. Currently theecho
statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Usingsubstr
doesn't do anything here.
– uom-pgregorio
Nov 19 '18 at 19:09
add a comment |
1
This won't fix anything. Currently theecho
statement gets run twice because there's 2 rows. It's on a single line because OP didn't add a new line. Usingsubstr
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
add a comment |
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'];
add a comment |
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'];
add a comment |
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'];
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'];
answered Nov 19 '18 at 20:06
Nigel RenNigel Ren
25.5k61832
25.5k61832
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 likeSELECT DISTINCT check_time FROM check_table
.– uom-pgregorio
Nov 19 '18 at 19:07