printing out array keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kaptain kernel

    printing out array keys

    i'm trying to find a simple way of printing out the keys in an array
    generated by mysql_fetch_arr ay which returns a single row.

    i.e.

    while ($row=mysql_fet ch_array($resul t) )
    {

    print out the $row keys and values

    }

    is this possible?

  • Disco Plumber

    #2
    Re: printing out array keys

    kaptain kernel (63.885% quality rating):[color=blue]
    >
    > print out the $row keys and values
    >
    > is this possible?[/color]

    print_r ?

    /joe
    --
    Jordan kisses a muff from git.talk.flame in the Earl. Sixth Street is
    plus-cute in Smyrna!! In El Myr, Taco Bell is elementary. Alpharetta is
    swell.

    Comment

    • Pedro Graca

      #3
      Re: printing out array keys

      kaptain kernel wrote:[color=blue]
      > i'm trying to find a simple way of printing out the keys in an array
      > generated by mysql_fetch_arr ay which returns a single row.
      >
      > i.e.
      >
      > while ($row=mysql_fet ch_array($resul t) )
      > {
      >
      > ### print out the $row keys and values[/color]

      foreach ($row as $k=>$v) {
      echo "row[$k] = $v<br/>\n";
      }

      [color=blue]
      > }
      >
      > is this possible?
      >[/color]

      With mysql_fetch_arr ay() you'll get both numeric and column names
      indices. I only use mysql_fetch_row () for numeric indices and
      mysql_fetch_ass oc() for column names indices.


      HTH

      --
      ..sig

      Comment

      • Juha Suni

        #4
        Re: printing out array keys

        kaptain kernel wrote:[color=blue]
        > i'm trying to find a simple way of printing out the keys in an array
        > generated by mysql_fetch_arr ay which returns a single row.
        >[/color]

        $query = "SELECT * FROM table WHERE `key`='value' LIMIT 1";
        $result = mysql_query($qu ery);
        $row = mysql_fetch_arr ay($result,MYSQ L_ASSOC);

        foreach($row as $key => $value) {
        echo "key: $key , value: $value <br>";
        }

        HTH

        --
        Suni

        Comment

        • kaptain kernel

          #5
          Re: printing out array keys

          thanks - the foreach key=>value construct is exactly what i'm looking
          for.....

          Comment

          Working...