Display sql query output in html table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry M. Gartner

    Display sql query output in html table

    Greetings:

    As evident from a previous post, I am a php noob. I would like to
    display MySQL query results in an html table with one of the row values as a
    category and the rest of the data displayed under the relevant category.

    I can get as far as displaying the data in a nice readable format but I
    don't know how to have the records placed under their corresponding
    category. This is my code thus far (sans the html output):

    ....ORDER BY cat ASC';
    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
    $row["desc"]);
    }

    As you can see, this only outputs each record with the selected rows but
    we show multiple instances of the same category. I know why this works the
    way it does, I just don't know how to make it work the way I want. Advice
    is appreciated. Thanks in advance.

    Also, any good links for understanding and using arrays are welcome.
    --

    Regards,

    Jerry M. Gartner


  • Jerry Stuckle

    #2
    Re: Display sql query output in html table

    Jerry M. Gartner wrote:[color=blue]
    > Greetings:
    >
    > As evident from a previous post, I am a php noob. I would like to
    > display MySQL query results in an html table with one of the row values as a
    > category and the rest of the data displayed under the relevant category.
    >
    > I can get as far as displaying the data in a nice readable format but I
    > don't know how to have the records placed under their corresponding
    > category. This is my code thus far (sans the html output):
    >
    > ...ORDER BY cat ASC';
    > while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    > printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
    > $row["desc"]);
    > }
    >
    > As you can see, this only outputs each record with the selected rows but
    > we show multiple instances of the same category. I know why this works the
    > way it does, I just don't know how to make it work the way I want. Advice
    > is appreciated. Thanks in advance.
    >
    > Also, any good links for understanding and using arrays are welcome.[/color]

    Something like:

    $cat = ""; // Or any value you would never have for a category
    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    if ($row['cat'] != $cat) {
    echo $row['cat'] . ' ';
    $cat = $row['cat'];
    }
    echo 'Class: ' . $row['title'] . "Descriptio n" . $row['desc'];
    }

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Jerry M. Gartner

      #3
      Re: Display sql query output in html table

      That did the trick thanks much for the input.

      --

      Regards,

      Jerry M. Gartner

      "Jerry Stuckle" <jstucklex@attg lobal.net> wrote in message
      news:d4ednVp2qf 62MQHZnZ2dnUVZ_ tidnZ2d@comcast .com...[color=blue]
      > Jerry M. Gartner wrote:[color=green]
      >> Greetings:
      >>
      >> As evident from a previous post, I am a php noob. I would like to
      >> display MySQL query results in an html table with one of the row values
      >> as a category and the rest of the data displayed under the relevant
      >> category.
      >>
      >> I can get as far as displaying the data in a nice readable format but
      >> I don't know how to have the records placed under their corresponding
      >> category. This is my code thus far (sans the html output):
      >>
      >> ...ORDER BY cat ASC';
      >> while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
      >> printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
      >> $row["desc"]);
      >> }
      >>
      >> As you can see, this only outputs each record with the selected rows
      >> but we show multiple instances of the same category. I know why this
      >> works the way it does, I just don't know how to make it work the way I
      >> want. Advice is appreciated. Thanks in advance.
      >>
      >> Also, any good links for understanding and using arrays are welcome.[/color]
      >
      > Something like:
      >
      > $cat = ""; // Or any value you would never have for a category
      > while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
      > if ($row['cat'] != $cat) {
      > echo $row['cat'] . ' ';
      > $cat = $row['cat'];
      > }
      > echo 'Class: ' . $row['title'] . "Descriptio n" . $row['desc'];
      > }
      >
      > --
      > =============== ===
      > Remove the "x" from my email address
      > Jerry Stuckle
      > JDS Computer Training Corp.
      > jstucklex@attgl obal.net
      > =============== ===[/color]


      Comment

      Working...