Problem with table...

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

    Problem with table...

    I wrote a php script that reads some dara from database and displays it as
    a table:
    The problem is that the data are showing in table rows Is it possible to
    display it as a new colum next to an existing one?


    Here is php code::


    echo "<table align=\"center\ " width=\"100%\"> ";
    echo"<tr><td>Ro om:</td></tr>";
    echo"<tr><td>Pr ice:</td></tr>";
    echo"<tr><td>Ho w many rooms?:</td></tr>";

    // data display

    $wynik2=mysql_q uery($hotel_que ry2);
    while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
    {
    echo"<tr><td>". return_data($wi ersz2[0])."</td></tr>";
    echo"<tr><td >".return_data( $wiersz2[1])."</td></tr>";
    echo"<tr><td >".return_data( $wiersz2[2])."</td></tr>";
    }
    echo "</table>";

    Each while pass creates 3 rows. Is it possible to make new column (with 3
    rows) next to the one that already exists?

    Thanks.
    Leszek


  • Beauregard T. Shagnasty

    #2
    Re: Problem with table...

    Leszek wrote:
    [color=blue]
    > I wrote a php script that reads some dara from database and displays it as
    > a table:
    > The problem is that the data are showing in table rows Is it possible to
    > display it as a new colum next to an existing one?
    >
    > Here is php code::[/color]

    Let me edit your code. I'll remove several <tr> and </tr>:

    echo "<table align=\"center\ " width=\"100%\"> ";
    echo"<tr><td>Ro om:</td>";
    echo"<td>Price: </td>";
    echo"<td>How many rooms?:</td></tr>";

    // data display

    $wynik2=mysql_q uery($hotel_que ry2);
    while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
    {
    echo"<tr><td>". return_data($wi ersz2[0])."</td>";
    echo"<td >".return_data( $wiersz2[1])."</td>";
    echo"<td >".return_data( $wiersz2[2])."</td></tr>";
    }
    echo "</table>";
    [color=blue]
    > Each while pass creates 3 rows. Is it possible to make new column (with 3
    > rows) next to the one that already exists?[/color]

    Is this what you mean? <tr> starts a new row; you do not want to put
    each "column" in its own row.

    --
    -bts
    -Warning: I brake for lawn deer

    Comment

    • Leszek

      #3
      Re: Problem with table...

      I want to get this:

      //Column1 Column2
      Room: return_data($wi ersz2[0])
      Price: return_data($wi ersz2[1])
      How many?: return_data($wi ersz2[2])

      But using my code i'm getting:

      Room:
      Price:
      How many?:
      return_data($wi ersz2[0])
      return_data($wi ersz2[1])
      return_data($wi ersz2[2])

      Pozdrawiam.
      Leszek


      Comment

      • Barbara de Zoete

        #4
        Re: Problem with table...

        On Fri, 06 Jan 2006 16:37:02 +0100, Beauregard T. Shagnasty
        <a.nony.mous@ex ample.invalid> wrote:
        [color=blue]
        > Is this what you mean? <tr> starts a new row; you do not want to put
        > each "column" in its own row.[/color]

        <prediction>
        Next question: How do I display the data cells in a table underneith one
        an other, like it was a column (instead next to eachother in a row)?
        </prediction>




        --
        ,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
        | weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
        | webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
        |zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
        `-------------------------------------------------- --<--@ ------------'

        Comment

        • Carl

          #5
          Re: Problem with table...

          Leszek wrote:[color=blue]
          > I wrote a php script that reads some dara from database and displays it as
          > a table:
          > The problem is that the data are showing in table rows Is it possible to
          > display it as a new colum next to an existing one?
          >
          >
          > Here is php code::
          >
          >
          > echo "<table align=\"center\ " width=\"100%\"> ";
          > echo"<tr><td>Ro om:</td></tr>";
          > echo"<tr><td>Pr ice:</td></tr>";
          > echo"<tr><td>Ho w many rooms?:</td></tr>";
          >
          > // data display
          >
          > $wynik2=mysql_q uery($hotel_que ry2);
          > while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
          > {
          > echo"<tr><td>". return_data($wi ersz2[0])."</td></tr>";
          > echo"<tr><td >".return_data( $wiersz2[1])."</td></tr>";
          > echo"<tr><td >".return_data( $wiersz2[2])."</td></tr>";
          > }
          > echo "</table>";
          >
          > Each while pass creates 3 rows. Is it possible to make new column (with 3
          > rows) next to the one that already exists?
          >
          > Thanks.
          > Leszek
          >
          >[/color]

          Leszek,

          Hint:
          echo "<tr> <td>Room:</td> <td>".return_da ta($wiersz2[0])."</td> </tr>";

          Cheers,
          Carl.

          Comment

          • shagnast

            #6
            Re: Problem with table...

            Barbara de Zoete wrote:[color=blue]
            > On Fri, 06 Jan 2006 16:37:02 +0100, Beauregard T. Shagnasty
            > <a.nony.mous@ex ample.invalid> wrote:
            >[color=green]
            >> Is this what you mean? <tr> starts a new row; you do not want to
            >> put each "column" in its own row.[/color]
            >
            > <prediction> Next question: How do I display the data cells in a
            > table underneith one an other, like it was a column (instead next to
            > eachother in a row)? </prediction>[/color]

            You are probably correct. :-0


            echo "<table align=\"center\ " width=\"100%\"> ";
            // data display
            $wynik2=mysql_q uery($hotel_que ry2);
            while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
            {
            echo"<tr><td>Ro om:</td><td>.return_ data($wiersz2[0])."</td></tr>";
            echo"<tr><td>Pr ice:</td><td >".return_data( $wiersz2[1])."</td></tr>";
            echo"<tr><td>Ho w many
            rooms?:</td><td>".return _data($wiersz2[2])."</td></tr>";
            }
            echo "</table>";


            This of course means Leszek only ever expects three items to be returned
            by the query. The above is not the normal way to display a table of data.

            --
            -bts
            -Warning: I brake for lawn deer

            Comment

            • Kevin H. Feeley

              #7
              Re: Problem with table...

              Leszek wrote:
              [color=blue]
              > I want to get this:
              >
              > //Column1 Column2
              > Room: return_data($wi ersz2[0])
              > Price: return_data($wi ersz2[1])
              > How many?: return_data($wi ersz2[2])
              >
              > But using my code i'm getting:
              >
              > Room:
              > Price:
              > How many?:
              > return_data($wi ersz2[0])
              > return_data($wi ersz2[1])
              > return_data($wi ersz2[2])
              >
              > Pozdrawiam.
              > Leszek[/color]

              Two basic ways of handling this. One is a html solution, the other array
              based.

              HTML Solution:
              Nested tables.
              <table>
              <tr>
              <td>
              <table><tr><td> Room:</td></tr><tr><td>Pric e</td></tr><tr><td>How
              many?:</td></tr></table>
              </td>
              <td>
              <table><tr><td> return_data($wi ersz
              [0])</td></tr><tr><td>retu rn_data($wiersz
              [1])</td></tr><tr><td>retu rn_data($wiersz 2[2])</td></tr></table>
              </td>
              </tr>
              </table>

              Array based:

              /* Toss both sets of values (labels and data) into arrays */
              $labels=array(' Room:','Price:' ,'How many?:');
              $column[1]=array(return_d ata($wiersz2[0]),return_data($ wiersz
              [1]),return_data($ wiersz2[3]));
              $column[2]=array(return_d ata($ziersz2[0]),return_data($ ziersz
              [1]),return_data($ ziersz2[2]));

              echo("<table>") ;
              for($i=0;$i<=(c ount($labels)-1);$i++){
              echo("<tr><td>{ $labels[$i]}</td>");
              foreach($column AS $col){
              <td>$col[$i]</td>
              }
              echo("</tr>");
              }
              echo("</table>");

              Comment

              • jukka

                #8
                Re: Problem with table...

                Leszek wrote:[color=blue]
                > I wrote a php script that reads some dara from database and displays it as
                > a table:
                > The problem is that the data are showing in table rows Is it possible to
                > display it as a new colum next to an existing one?
                >
                >
                > Here is php code::
                >
                >
                > echo "<table align=\"center\ " width=\"100%\"> ";
                > echo"<tr><td>Ro om:</td></tr>";
                > echo"<tr><td>Pr ice:</td></tr>";
                > echo"<tr><td>Ho w many rooms?:</td></tr>";
                >
                > // data display
                >
                > $wynik2=mysql_q uery($hotel_que ry2);
                > while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
                > {
                > echo"<tr><td>". return_data($wi ersz2[0])."</td></tr>";
                > echo"<tr><td >".return_data( $wiersz2[1])."</td></tr>";
                > echo"<tr><td >".return_data( $wiersz2[2])."</td></tr>";
                > }
                > echo "</table>";
                >
                > Each while pass creates 3 rows. Is it possible to make new column (with 3
                > rows) next to the one that already exists?
                >
                > Thanks.
                > Leszek
                >
                >[/color]
                maybe:

                echo "<table align=\"center\ " width=\"100%\"> ";

                // data display

                $wynik2=mysql_q uery($hotel_que ry2);
                while($wiersz2= mysql_fetch_arr ay($wynik2,MYSQ L_NUM))
                {
                echo "<tr><td>Ro om:</td><td>".return _data($wiersz2[0])."</td></tr>";
                echo "<tr><td>Price: </td><td>".return _data($wiersz2[1])."</td></tr>";
                echo "<tr><td>Ho w many
                rooms?:</td><td>".return _data($wiersz2[2])."</td></tr>";
                }
                echo "</table>";

                Comment

                • Beauregard T. Shagnasty

                  #9
                  Re: Problem with table...

                  jukka wrote:
                  [color=blue]
                  > maybe:
                  >
                  > echo " ...[/color]

                  Heh, I believe you "echoed" my code from yesterday. :-)

                  --
                  -bts
                  -Warning: I brake for lawn deer

                  Comment

                  • jukka

                    #10
                    Re: Problem with table...

                    Beauregard T. Shagnasty wrote:[color=blue]
                    > jukka wrote:
                    >
                    >[color=green]
                    >>maybe:
                    >>
                    >>echo " ...[/color]
                    >
                    >
                    > Heh, I believe you "echoed" my code from yesterday. :-)
                    >[/color]
                    hehe pun pun. But i think your code goes:
                    |Room |Price |Quantity|
                    | 12 | $100 | 1 |

                    mine (or tries to):
                    |Room | 12|
                    |Price | $100|
                    |Quantity | 1|

                    Comment

                    • Beauregard T. Shagnasty

                      #11
                      Re: Problem with table...

                      jukka wrote:
                      [color=blue]
                      > Beauregard T. Shagnasty wrote:[color=green]
                      >> jukka wrote:
                      >>[color=darkred]
                      >>>maybe:
                      >>>
                      >>>echo " ...[/color]
                      >>
                      >> Heh, I believe you "echoed" my code from yesterday. :-)
                      >>[/color]
                      > hehe pun pun. But i think your code goes:
                      >|Room |Price |Quantity|
                      >| 12 | $100 | 1 |
                      >
                      > mine (or tries to):
                      >|Room | 12|
                      >|Price | $100|
                      >|Quantity | 1|[/color]

                      I was referring to my second post, which got sent under the name
                      "shagnast" (was having trouble with my usual news server at the time).
                      In that revision, it will print out as your "mine" example.

                      --
                      -bts
                      -Warning: I brake for lawn deer

                      Comment

                      • jukka

                        #12
                        Re: Problem with table...

                        Beauregard T. Shagnasty wrote:[color=blue]
                        > jukka wrote:
                        >
                        >[color=green]
                        >>Beauregard T. Shagnasty wrote:
                        >>[color=darkred]
                        >>>jukka wrote:
                        >>>
                        >>>
                        >>>>maybe:
                        >>>>
                        >>>>echo " ...
                        >>>
                        >>>Heh, I believe you "echoed" my code from yesterday. :-)
                        >>>[/color]
                        >>
                        >>hehe pun pun. But i think your code goes:
                        >>|Room |Price |Quantity|
                        >>| 12 | $100 | 1 |
                        >>
                        >>mine (or tries to):
                        >>|Room | 12|
                        >>|Price | $100|
                        >>|Quantity | 1|[/color]
                        >
                        >
                        > I was referring to my second post, which got sent under the name
                        > "shagnast" (was having trouble with my usual news server at the time).
                        > In that revision, it will print out as your "mine" example.
                        >[/color]
                        ah yes, i see it now :)

                        Comment

                        Working...