Question:

Help with PHP array problem?

by  |  earlier

0 LIKES UnLike

When I call mysql_fetch_array() for each row of a table in my database, I get an array that has both the intended associative array key:value pairs for each column and the columns as numeric indexes. Problem is, when I try to send this array back to the client via. json_encode() in PHP, the key:value pairs of the array bug up in javascript's eval() function (at least, I THINK that was what was going wrong...).

I JUST want the numeric indexes. What's a good way to skim off the key:values from that array before sending it through json_encode()?

 Tags:

   Report

1 ANSWERS


  1. The problem is probably in your query: you want a non-associative array.

    $sql = "select `colname` from `tablename` where ... "

    $list = mysql_query($sql);

    $ndx = 0;

    while ($lst = mysql_fetch_array($list))

    $colcontents[$ndx++] = $lst[0];

    mysql_free_result ($list);

    Now, $colcontents [ ] only contains the values you want to pass on...

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.