на стороне PHP API, у меня есть это:
$res = $db->query("SELECT count(upVote) FROM tbl_post_likers WHERE post_id='$pnum' AND upVote='true'");
$row = $res->fetchArray();
if($row[0] > 0){
$upVotes = $row[0];
$res = $db->query("SELECT count(downVote) FROM tbl_post_likers WHERE post_id='$pnum' AND downVote='true'");
$row = $res->fetchArray();
$downVotes = $row[0];
$tot = $upVotes + $downVotes;
$upVotesPer = ($upVotes * 100) / $tot;
$downVotesPer = ($downVotes * 100) / $tot;
return $upVotesPer - $downVotesPer;
}else if ($row[0] == 0){
return 0;
}
и я попытался вернуть некоторые данные в виде массива из API.
и на стороне JavaScript, когда я JSON.parse
возвращенные данные, я получаю все данные правильно, как показано ниже:
например:
0: [...],
1: [...],
2: 0
ноль - return 0;
со стороны php,
Проблема в том, что когда I console.log
3-е свойство это undefined
или когда I parseInt
оно возвращает NaN
, а 3-е свойство возвращаемых данных, как показано, равно нулю.
это фактический console.log
:
0
:
"{"0":2,"id":2,"1":"0.jpg","image":"0.jpg","2":"Proj 1","title":"Proj 1","3":"some description here about the course!","desc":"some description here about the course!","4":"sinawic","teacher":"sinawic","5":0,"sell_count":0,"6":"1997.05.05","date_released":"1997.05.05","7":97,"preview":97,"8":0,"likes":0,"9":0,"post_point":0,"10":0,"post_cash":0}"
1
:
"["jquery","vue"]"
2
:
"[{"lesson_num":1,"topic_name":"pre"}]"
3
:
"{"0":"sinawic","username":"sinawic","1":"web design, React, VUE, javascript","fields_name":"web design, React, VUE, javascript","2":"this is all about me, oke? call me maybe","description":"this is all about me, oke? call me maybe","3":"85%, 53%, 36%, 74%, 17%","ranks":"85%, 53%, 36%, 74%, 17%"}"
5
:
0
и это данные echo
к API:
{"0":"{\"0\":2,\"id\":2,\"1\":\"0.jpg\",\"image\":\"0.jpg\",\"2\":\"Proj 1\",\"title\":\"Proj 1\",\"3\":\"some description here about the course!\",\"desc\":\"some description here about the course!\",\"4\":\"sinawic\",\"teacher\":\"sinawic\",\"5\":0,\"sell_count\":0,\"6\":\"1997.05.05\",\"date_released\":\"1997.05.05\",\"7\":98,\"preview\":98,\"8\":0,\"likes\":0,\"9\":0,\"post_point\":0,\"10\":0,\"post_cash\":0}","1":"[\"jquery\",\"vue\"]","2":"[{\"lesson_num\":1,\"topic_name\":\"pre\"}]","3":"{\"0\":\"sinawic\",\"username\":\"sinawic\",\"1\":\"web design, React, VUE, javascript\",\"fields_name\":\"web design, React, VUE, javascript\",\"2\":\"this is all about me, oke? call me maybe\",\"description\":\"this is all about me, oke? call me maybe\",\"3\":\"85%, 53%, 36%, 74%, 17%\",\"ranks\":\"85%, 53%, 36%, 74%, 17%\"}","5":0}
как я мог это решить.