json_encode is returning NULL?

前端 未结 10 2036
[愿得一人]
[愿得一人] 2020-11-22 12:22

For some reason the item \"description\" returns NULL with the following code:



        
10条回答
  •  时光说笑
    2020-11-22 12:59

    AHHH!!! This looks so wrong it hurts my head. Try something more like this...

    
    
    • When iterating over mysql_num_rows you should use < not <=. You should also cache this value (save it to a variable) instead of having it re-count every loop. Who knows what it's doing under the hood... (might be efficient, I'm not really sure)
    • You don't need to copy out each value explicitly like that... you're just making this harder on yourself. If the query is returning more values than you've listed there, list only the ones you want in your SQL.
    • mysql_fetch_array returns the values both by key and by int. You not using the indices, so don't fetch em.

    If this really is a problem with json_encode, then might I suggest replacing the body of the loop with something like

    $rows[] = array_map('htmlentities',$row);
    

    Perhpas there are some special chars in there that are mucking things up...

提交回复
热议问题