difference between mysql_fetch_assoc and mysql_fetch_array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    difference between mysql_fetch_assoc and mysql_fetch_array

    Dear friends ,


    Plz any one tell me What is difference between mysql_fetch_ass oc and mysql_fetch_arr ay while both are return associtive array ?
  • jx2
    New Member
    • Feb 2007
    • 228

    #2
    Originally posted by sanjay123456
    Dear friends ,


    Plz any one tell me What is difference between mysql_fetch_ass oc and mysql_fetch_arr ay while both are return associtive array ?
    mysql_fetch_arr ay will return twice as much data!! and doesnt work well if you use foreach();
    simply try it for each of them!!
    [php]
    foreach($yourAr ray as $k =>$v){
    echo "$k => $v <br>";
    }
    [/php]

    jx2

    Comment

    • Lumpy
      New Member
      • Oct 2007
      • 69

      #3
      Straight from the php website...

      mysql_fetch_arr ay — Fetch a result row as an associative array, a numeric array, or both

      mysql_fetch_ass oc — Fetch a result row as an associative array

      I think what this is saying is that mysql_fetch_arr ay can be used like...
      [CODE=php]
      $row['fieldname']
      or
      $row[0]
      [/CODE]

      where mysql_fetch_ass oc can only be used like...
      [CODE=php]
      $row['fieldname']
      [/CODE]

      hope this helps.

      Comment

      • tolkienarda
        Contributor
        • Dec 2006
        • 316

        #4
        mysql fetch array function allows for two inputs the first is the result reasource, this is the only required field but you can enter what kind of array you would like, the default is MYSQL_BOTH which means it works as either kind of array or you can tell it to only use numbers or associative keys, the mysql fetch assoc function is the same as mysql fetch array with the MYSQL_ASSOC option.

        http://us2.php.net/manual/en/function.mysql-fetch-array.php
        http://us2.php.net/mysql_fetch_ass oc

        the manual for php is very useful and easy to read


        eric bressler

        Comment

        Working...