saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #1 I am using following php script and it is returning an array to me. How can i get the data out of this array as i am using j as httpjob, but httpjob does not have a get array type of method. $result = $conn->query("SELECT * FROM menuitems"); if ($result->num_rows > 0) { $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } echo $rows; $result->close(); i want trying to convert the array to string using json on the php script side but it is giving me error as json is not supported on the domain where my php script is running
I am using following php script and it is returning an array to me. How can i get the data out of this array as i am using j as httpjob, but httpjob does not have a get array type of method. $result = $conn->query("SELECT * FROM menuitems"); if ($result->num_rows > 0) { $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } echo $rows; $result->close(); i want trying to convert the array to string using json on the php script side but it is giving me error as json is not supported on the domain where my php script is running
DonManfred Expert Licensed User Longtime User Apr 2, 2020 #3 aeric said: Use echo json_encode() Click to expand... I suggest to use PHP: echo json_encode($rows); Upvote 0
saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #4 DonManfred said: I suggest to use PHP: echo json_encode($rows); Click to expand... i tried that already, but it is giving me error on the server side, it seems that server does not recognize json Upvote 0
DonManfred said: I suggest to use PHP: echo json_encode($rows); Click to expand... i tried that already, but it is giving me error on the server side, it seems that server does not recognize json
DonManfred Expert Licensed User Longtime User Apr 2, 2020 #5 saeed10051 said: i tried that already, but it is giving me error on the server side Click to expand... WHERE is the errormessage? <-- !! saeed10051 said: it seems that server does not recognize json Click to expand... Your app gets the echo output. So it must be your app which must be able to read the json from your server. You are NOT giving any useful information to us to help you. Upvote 0
saeed10051 said: i tried that already, but it is giving me error on the server side Click to expand... WHERE is the errormessage? <-- !! saeed10051 said: it seems that server does not recognize json Click to expand... Your app gets the echo output. So it must be your app which must be able to read the json from your server. You are NOT giving any useful information to us to help you.
saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #6 DonManfred said: WHERE is the errormessage? <-- !! Your app gets the echo output. So it must be your app which must be able to read the json from your server. You are NOT giving any useful information to us to help you. Click to expand... when i am using following code if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } $res = jason_encode($rows); echo $res; $result->close(); $conn->close(); ?> i am getting following error on running it in the browser Connected to the database. Fatal error: Uncaught Error: Call to undefined function jason_encode() in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php:24 Stack trace: #0 {main} thrown in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php on line 24 $res = jason_encode($rows); is on line 24 Upvote 0
DonManfred said: WHERE is the errormessage? <-- !! Your app gets the echo output. So it must be your app which must be able to read the json from your server. You are NOT giving any useful information to us to help you. Click to expand... when i am using following code if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } $res = jason_encode($rows); echo $res; $result->close(); $conn->close(); ?> i am getting following error on running it in the browser Connected to the database. Fatal error: Uncaught Error: Call to undefined function jason_encode() in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php:24 Stack trace: #0 {main} thrown in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php on line 24 $res = jason_encode($rows); is on line 24
saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #7 However if i run following code if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } //$res = jason_encode($rows); echo $rows; $result->close(); $conn->close(); ?> i get following result on browser Connected to the database. Array Upvote 0
However if i run following code if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } //$res = jason_encode($rows); echo $rows; $result->close(); $conn->close(); ?> i get following result on browser Connected to the database. Array
saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #8 this means that an array is returned but how to catch this array using httpjob?? Upvote 0
udg Expert Licensed User Longtime User Apr 2, 2020 #9 What's in your real code, jason_encode or json_encode? Upvote 0
DonManfred Expert Licensed User Longtime User Apr 2, 2020 #10 saeed10051 said: Uncaught Error: Call to undefined function jason_encode() i Click to expand... When you copy a code someone give to you: I guggest to copy it correctly! DonManfred said: I suggest to use PHP: echo json_encode($rows); Click to expand... Compare this Code to the Code you are using! Last edited: Apr 2, 2020 Upvote 0
saeed10051 said: Uncaught Error: Call to undefined function jason_encode() i Click to expand... When you copy a code someone give to you: I guggest to copy it correctly! DonManfred said: I suggest to use PHP: echo json_encode($rows); Click to expand... Compare this Code to the Code you are using!
DonManfred Expert Licensed User Longtime User Apr 2, 2020 #11 saeed10051 said: if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } $res = jason_encode($rows); echo $res; $result->close(); $conn->close(); ?> Click to expand... Also Please use [CODE]code here...[/CODE] tags when posting code. Upvote 0
saeed10051 said: if ($result->num_rows > 0) { // output data of each row $rows = array(); while($r = $result->fetch_assoc()) { $rows[] = $r; } } else { echo "0 results"; } $res = jason_encode($rows); echo $res; $result->close(); $conn->close(); ?> Click to expand... Also Please use [CODE]code here...[/CODE] tags when posting code.
M martha Member Apr 2, 2020 #12 Check this line PHP: $res = jason_encode($rows); and replace with PHP: $res = json_encode($rows); jason_encode has an extra "a". Upvote 0
Check this line PHP: $res = jason_encode($rows); and replace with PHP: $res = json_encode($rows); jason_encode has an extra "a".
saeed10051 Active Member Licensed User Longtime User Apr 2, 2020 #13 martha said: Check this line PHP: $res = jason_encode($rows); and replace with PHP: $res = json_encode($rows); jason_encode has an extra "a". Click to expand... Thanks All, yes this was the mistake one extra a was screwing everything. It is working now. Upvote 0
martha said: Check this line PHP: $res = jason_encode($rows); and replace with PHP: $res = json_encode($rows); jason_encode has an extra "a". Click to expand... Thanks All, yes this was the mistake one extra a was screwing everything. It is working now.