Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I try to print_r mysql_fetch_array of a sql query, I get this result.

Array
(
    [0] => 1
    [id] => 1
    [1] => 2011
    [publish_date] => 2011
    [2] => Posted
    [status] => Posted
    [3] => test
    [post_title] => test
    [4] =>  testy test test testtttttt
    [post_text] =>  testy test test testtttttt
    [5] => true
    [post_comments] => true
    [6] => 21
    [reviews] => 21
    [7] => 1
    [network_id] => 1
    [8] => 3
    [views] => 3
    [9] => 0
    [comments] => 0
)

All I want is only string array keys so how can I convert this result to that?

Array
(
    [id] => 1
    [publish_date] => 2011
    [status] => Posted
    [post_title] => test
    [post_text] =>  testy test test testtttttt
    [post_comments] => true
    [reviews] => 21
    [network_id] => 1
    [views] => 3
    [comments] => 0
)
share|improve this question

3 Answers

up vote 4 down vote accepted

Use mysql_fetch_assoc

share|improve this answer

instead of mysql_fetch_array use mysql_fetch_assoc. thats it.

share|improve this answer

Use mysql_fetch_assoc function

or

Use second parameter for mysql_fetch_array function: MYSQL_ASSOC

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.