array isn´t getting mysql data php











up vote
-1
down vote

favorite












I have had my webpages in diferents hostings, and in all this hosting it was working fine, a few days a go, I bought one hosting in godaddy, I made the backup of the database, and then I put it in the hosting of godaddy, but I have a problem, when I am trying to put de data of my query into an array to convert it in a json, it didnt show something. in the other hosting and localhost it is working fine.



$sql1 = "SELECT * FROM table Where somthing='$something'";
$ejecutar_sql1=mysqli_query($con,$sql1);

if (mysqli_num_rows($ejecutar_sql1) > 0){
$rawdata = array();
$i=0;
while($row = mysqli_fetch_array($ejecutar_sql1))
{
$rawdata[$i] = $row;
$i++;
}
echo json_encode($rawdata);
}



  • If I put echo mysqli_num_rows($ejecutar_sql1); its show me 270.

  • If I put echo $row["id"]; inside the while, it show me all the id.

  • If I put echo count($rawdata); its show me 270.

  • But the echo json_encode($rawdata); it didnt show something.


thanks for the help










share|improve this question
























  • Should somthing in your query be something ?
    – rpm192
    Nov 9 at 22:34










  • @rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
    – joshrs
    Nov 9 at 22:38










  • Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
    – Funk Forty Niner
    Nov 9 at 23:03






  • 1




    Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
    – RiggsFolly
    Nov 10 at 0:18






  • 1




    Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
    – cale_b
    Nov 10 at 0:19















up vote
-1
down vote

favorite












I have had my webpages in diferents hostings, and in all this hosting it was working fine, a few days a go, I bought one hosting in godaddy, I made the backup of the database, and then I put it in the hosting of godaddy, but I have a problem, when I am trying to put de data of my query into an array to convert it in a json, it didnt show something. in the other hosting and localhost it is working fine.



$sql1 = "SELECT * FROM table Where somthing='$something'";
$ejecutar_sql1=mysqli_query($con,$sql1);

if (mysqli_num_rows($ejecutar_sql1) > 0){
$rawdata = array();
$i=0;
while($row = mysqli_fetch_array($ejecutar_sql1))
{
$rawdata[$i] = $row;
$i++;
}
echo json_encode($rawdata);
}



  • If I put echo mysqli_num_rows($ejecutar_sql1); its show me 270.

  • If I put echo $row["id"]; inside the while, it show me all the id.

  • If I put echo count($rawdata); its show me 270.

  • But the echo json_encode($rawdata); it didnt show something.


thanks for the help










share|improve this question
























  • Should somthing in your query be something ?
    – rpm192
    Nov 9 at 22:34










  • @rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
    – joshrs
    Nov 9 at 22:38










  • Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
    – Funk Forty Niner
    Nov 9 at 23:03






  • 1




    Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
    – RiggsFolly
    Nov 10 at 0:18






  • 1




    Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
    – cale_b
    Nov 10 at 0:19













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have had my webpages in diferents hostings, and in all this hosting it was working fine, a few days a go, I bought one hosting in godaddy, I made the backup of the database, and then I put it in the hosting of godaddy, but I have a problem, when I am trying to put de data of my query into an array to convert it in a json, it didnt show something. in the other hosting and localhost it is working fine.



$sql1 = "SELECT * FROM table Where somthing='$something'";
$ejecutar_sql1=mysqli_query($con,$sql1);

if (mysqli_num_rows($ejecutar_sql1) > 0){
$rawdata = array();
$i=0;
while($row = mysqli_fetch_array($ejecutar_sql1))
{
$rawdata[$i] = $row;
$i++;
}
echo json_encode($rawdata);
}



  • If I put echo mysqli_num_rows($ejecutar_sql1); its show me 270.

  • If I put echo $row["id"]; inside the while, it show me all the id.

  • If I put echo count($rawdata); its show me 270.

  • But the echo json_encode($rawdata); it didnt show something.


thanks for the help










share|improve this question















I have had my webpages in diferents hostings, and in all this hosting it was working fine, a few days a go, I bought one hosting in godaddy, I made the backup of the database, and then I put it in the hosting of godaddy, but I have a problem, when I am trying to put de data of my query into an array to convert it in a json, it didnt show something. in the other hosting and localhost it is working fine.



$sql1 = "SELECT * FROM table Where somthing='$something'";
$ejecutar_sql1=mysqli_query($con,$sql1);

if (mysqli_num_rows($ejecutar_sql1) > 0){
$rawdata = array();
$i=0;
while($row = mysqli_fetch_array($ejecutar_sql1))
{
$rawdata[$i] = $row;
$i++;
}
echo json_encode($rawdata);
}



  • If I put echo mysqli_num_rows($ejecutar_sql1); its show me 270.

  • If I put echo $row["id"]; inside the while, it show me all the id.

  • If I put echo count($rawdata); its show me 270.

  • But the echo json_encode($rawdata); it didnt show something.


thanks for the help







php mysql arrays json mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 4:42









paulsm4

76.4k999124




76.4k999124










asked Nov 9 at 22:31









joshrs

134




134












  • Should somthing in your query be something ?
    – rpm192
    Nov 9 at 22:34










  • @rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
    – joshrs
    Nov 9 at 22:38










  • Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
    – Funk Forty Niner
    Nov 9 at 23:03






  • 1




    Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
    – RiggsFolly
    Nov 10 at 0:18






  • 1




    Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
    – cale_b
    Nov 10 at 0:19


















  • Should somthing in your query be something ?
    – rpm192
    Nov 9 at 22:34










  • @rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
    – joshrs
    Nov 9 at 22:38










  • Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
    – Funk Forty Niner
    Nov 9 at 23:03






  • 1




    Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
    – RiggsFolly
    Nov 10 at 0:18






  • 1




    Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
    – cale_b
    Nov 10 at 0:19
















Should somthing in your query be something ?
– rpm192
Nov 9 at 22:34




Should somthing in your query be something ?
– rpm192
Nov 9 at 22:34












@rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
– joshrs
Nov 9 at 22:38




@rpm192 this query is an example, that was the reason that I put that it is show me the number of row of my query it is gettin the data of my database but $rawdata didnt show the info
– joshrs
Nov 9 at 22:38












Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
– Funk Forty Niner
Nov 9 at 23:03




Enable error reporting and mysqli_error($con) see what that shows. I've tested your code (also) with no problems.
– Funk Forty Niner
Nov 9 at 23:03




1




1




Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
– RiggsFolly
Nov 10 at 0:18




Error checking but if you cannot be bothered, Add ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors.
– RiggsFolly
Nov 10 at 0:18




1




1




Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
– cale_b
Nov 10 at 0:19




Nobody's going to say this but: The problem is GoDaddy. They are the worst host on the planet. Run (don't walk) to a different host.
– cale_b
Nov 10 at 0:19












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










OK -




  1. Your code worked fine on other hosts, before you moved to GoDaddy, correct?


  2. You believe that you imported the data correctly - because you're able to fetch 270 rows. Correct?


  3. The only thing that's failing is json_encode(), correct?



SUGGESTIONS:




  • Check the encoding: php JSON_encode not working


  • Apply error handling to json_encode. For example, echo json_last_error() in your PHP. You might also consider adding JSON_THROW_ON_ERROR option parameter.







share|improve this answer





















  • I tried with this post, but it show that its ok, it doesnt has problem with the encode
    – joshrs
    Nov 9 at 23:05










  • Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
    – paulsm4
    Nov 10 at 1:13












  • I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
    – joshrs
    Nov 10 at 2:18










  • I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
    – paulsm4
    Nov 10 at 4:39












  • thank you very much
    – joshrs
    Nov 10 at 15:36


















up vote
-2
down vote













you need to shift (remove) the first object of the array
use firstly



<?php array_shift($rawdata);?>


then you use what you want



 echo json_encode($rawdata);





share|improve this answer

















  • 2




    What problem would this solve?
    – miken32
    Nov 9 at 22:46











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',
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%2f53234110%2farray-isn%25c2%25b4t-getting-mysql-data-php%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








up vote
1
down vote



accepted










OK -




  1. Your code worked fine on other hosts, before you moved to GoDaddy, correct?


  2. You believe that you imported the data correctly - because you're able to fetch 270 rows. Correct?


  3. The only thing that's failing is json_encode(), correct?



SUGGESTIONS:




  • Check the encoding: php JSON_encode not working


  • Apply error handling to json_encode. For example, echo json_last_error() in your PHP. You might also consider adding JSON_THROW_ON_ERROR option parameter.







share|improve this answer





















  • I tried with this post, but it show that its ok, it doesnt has problem with the encode
    – joshrs
    Nov 9 at 23:05










  • Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
    – paulsm4
    Nov 10 at 1:13












  • I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
    – joshrs
    Nov 10 at 2:18










  • I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
    – paulsm4
    Nov 10 at 4:39












  • thank you very much
    – joshrs
    Nov 10 at 15:36















up vote
1
down vote



accepted










OK -




  1. Your code worked fine on other hosts, before you moved to GoDaddy, correct?


  2. You believe that you imported the data correctly - because you're able to fetch 270 rows. Correct?


  3. The only thing that's failing is json_encode(), correct?



SUGGESTIONS:




  • Check the encoding: php JSON_encode not working


  • Apply error handling to json_encode. For example, echo json_last_error() in your PHP. You might also consider adding JSON_THROW_ON_ERROR option parameter.







share|improve this answer





















  • I tried with this post, but it show that its ok, it doesnt has problem with the encode
    – joshrs
    Nov 9 at 23:05










  • Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
    – paulsm4
    Nov 10 at 1:13












  • I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
    – joshrs
    Nov 10 at 2:18










  • I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
    – paulsm4
    Nov 10 at 4:39












  • thank you very much
    – joshrs
    Nov 10 at 15:36













up vote
1
down vote



accepted







up vote
1
down vote



accepted






OK -




  1. Your code worked fine on other hosts, before you moved to GoDaddy, correct?


  2. You believe that you imported the data correctly - because you're able to fetch 270 rows. Correct?


  3. The only thing that's failing is json_encode(), correct?



SUGGESTIONS:




  • Check the encoding: php JSON_encode not working


  • Apply error handling to json_encode. For example, echo json_last_error() in your PHP. You might also consider adding JSON_THROW_ON_ERROR option parameter.







share|improve this answer












OK -




  1. Your code worked fine on other hosts, before you moved to GoDaddy, correct?


  2. You believe that you imported the data correctly - because you're able to fetch 270 rows. Correct?


  3. The only thing that's failing is json_encode(), correct?



SUGGESTIONS:




  • Check the encoding: php JSON_encode not working


  • Apply error handling to json_encode. For example, echo json_last_error() in your PHP. You might also consider adding JSON_THROW_ON_ERROR option parameter.








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 22:39









paulsm4

76.4k999124




76.4k999124












  • I tried with this post, but it show that its ok, it doesnt has problem with the encode
    – joshrs
    Nov 9 at 23:05










  • Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
    – paulsm4
    Nov 10 at 1:13












  • I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
    – joshrs
    Nov 10 at 2:18










  • I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
    – paulsm4
    Nov 10 at 4:39












  • thank you very much
    – joshrs
    Nov 10 at 15:36


















  • I tried with this post, but it show that its ok, it doesnt has problem with the encode
    – joshrs
    Nov 9 at 23:05










  • Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
    – paulsm4
    Nov 10 at 1:13












  • I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
    – joshrs
    Nov 10 at 2:18










  • I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
    – paulsm4
    Nov 10 at 4:39












  • thank you very much
    – joshrs
    Nov 10 at 15:36
















I tried with this post, but it show that its ok, it doesnt has problem with the encode
– joshrs
Nov 9 at 23:05




I tried with this post, but it show that its ok, it doesnt has problem with the encode
– joshrs
Nov 9 at 23:05












Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
– paulsm4
Nov 10 at 1:13






Q: Are questions 1 and 2 correct? The code used to work, and you're successfully fetching data into $rawdata? Please confirm. Q: Have you TRIED adding json_last_error() yet? If json_last_error() returns anything, please copy/paste it into your post.
– paulsm4
Nov 10 at 1:13














I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
– joshrs
Nov 10 at 2:18




I solved the problem, some words had acents like corazón in the second o, but I dont know why in the other hosting I didnt have this problem and in godady yes
– joshrs
Nov 10 at 2:18












I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
– paulsm4
Nov 10 at 4:39






I'm glad you found the root cause. If you read the link I cited above, you'd see the accepted answer says Malformed UTF-8 characters, possibly incorrectly encoded. See also: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded. STRONG SUGGESTION: try to put good error checking/recovery throughout your code. Including things like json_last_error().
– paulsm4
Nov 10 at 4:39














thank you very much
– joshrs
Nov 10 at 15:36




thank you very much
– joshrs
Nov 10 at 15:36












up vote
-2
down vote













you need to shift (remove) the first object of the array
use firstly



<?php array_shift($rawdata);?>


then you use what you want



 echo json_encode($rawdata);





share|improve this answer

















  • 2




    What problem would this solve?
    – miken32
    Nov 9 at 22:46















up vote
-2
down vote













you need to shift (remove) the first object of the array
use firstly



<?php array_shift($rawdata);?>


then you use what you want



 echo json_encode($rawdata);





share|improve this answer

















  • 2




    What problem would this solve?
    – miken32
    Nov 9 at 22:46













up vote
-2
down vote










up vote
-2
down vote









you need to shift (remove) the first object of the array
use firstly



<?php array_shift($rawdata);?>


then you use what you want



 echo json_encode($rawdata);





share|improve this answer












you need to shift (remove) the first object of the array
use firstly



<?php array_shift($rawdata);?>


then you use what you want



 echo json_encode($rawdata);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 22:38









Abanoub Istfanous

1




1








  • 2




    What problem would this solve?
    – miken32
    Nov 9 at 22:46














  • 2




    What problem would this solve?
    – miken32
    Nov 9 at 22:46








2




2




What problem would this solve?
– miken32
Nov 9 at 22:46




What problem would this solve?
– miken32
Nov 9 at 22:46


















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%2f53234110%2farray-isn%25c2%25b4t-getting-mysql-data-php%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

Landwehr

Reims

Javascript gets undefined on array