printing collumn names then contents from mysql query

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

    printing collumn names then contents from mysql query

    how can i take every field from a table (where there are many) and
    without referencing by name (using a loop) echo there name in a td
    followed by the contents? i think the foreach statement is what im
    looking for? but i dont understand it.

    regards

    marc

  • Rik

    #2
    Re: printing collumn names then contents from mysql query

    monomaniac21 wrote:
    how can i take every field from a table (where there are many) and
    without referencing by name (using a loop) echo there name in a td
    followed by the contents? i think the foreach statement is what im
    looking for? but i dont understand it.

    $result = mysql_query'$qu ery);
    while($row = mysql_fetch_ass oc($result){
    echo '<tr>';
    foreach($row as $key =$value){
    echo "<td>{$key}:{$v alue}</td>";
    }
    echo '</tr>';
    }

    Grtz,
    --
    Rik Wasmus


    Comment

    • monomaniac21

      #3
      Re: printing collumn names then contents from mysql query

      Ive tried that Rik and it deesnt work quite right. it displays each
      collumn twice, once with a number as key and the value and again with
      the (intended) colname as key and value. How can i modify it to stop
      the first bit being output?


      Rik wrote:
      monomaniac21 wrote:
      how can i take every field from a table (where there are many) and
      without referencing by name (using a loop) echo there name in a td
      followed by the contents? i think the foreach statement is what im
      looking for? but i dont understand it.
      >
      >
      $result = mysql_query'$qu ery);
      while($row = mysql_fetch_ass oc($result){
      echo '<tr>';
      foreach($row as $key =$value){
      echo "<td>{$key}:{$v alue}</td>";
      }
      echo '</tr>';
      }
      >
      Grtz,
      --
      Rik Wasmus

      Comment

      • Rik

        #4
        Re: printing collumn names then contents from mysql query

        monomaniac21 wrote:

        Do not toppost please.
        Rik wrote:
        >monomaniac21 wrote:
        >>how can i take every field from a table (where there are many) and
        >>without referencing by name (using a loop) echo there name in a td
        >>followed by the contents? i think the foreach statement is what im
        >>looking for? but i dont understand it.
        >$result = mysql_query'$qu ery);
        >while($row = mysql_fetch_ass oc($result){
        > echo '<tr>';
        > foreach($row as $key =$value){
        > echo "<td>{$key}:{$v alue}</td>";
        > }
        > echo '</tr>';
        >}
        Ive tried that Rik and it deesnt work quite right. it displays each
        collumn twice, once with a number as key and the value and again with
        the (intended) colname as key and value. How can i modify it to stop
        the first bit being output?

        Use mysql_fetch_ass oc() as per my example instead of mysql_fetch_arr ay();

        Grtz,
        --
        Rik Wasmus


        Comment

        • monomaniac21

          #5
          Re: printing collumn names then contents from mysql query

          sorry had an urgent deadline with that one :-(

          Rik wrote:
          monomaniac21 wrote:
          >
          Do not toppost please.
          >
          Rik wrote:
          monomaniac21 wrote:
          >how can i take every field from a table (where there are many) and
          >without referencing by name (using a loop) echo there name in a td
          >followed by the contents? i think the foreach statement is what im
          >looking for? but i dont understand it.
          $result = mysql_query'$qu ery);
          while($row = mysql_fetch_ass oc($result){
          echo '<tr>';
          foreach($row as $key =$value){
          echo "<td>{$key}:{$v alue}</td>";
          }
          echo '</tr>';
          }
          Ive tried that Rik and it deesnt work quite right. it displays each
          collumn twice, once with a number as key and the value and again with
          the (intended) colname as key and value. How can i modify it to stop
          the first bit being output?
          >
          >
          Use mysql_fetch_ass oc() as per my example instead of mysql_fetch_arr ay();
          >
          Grtz,
          --
          Rik Wasmus

          Comment

          Working...