Problem with table...

Discussion in 'HTML' started by Leszek, Jan 6, 2006.

  1. Leszek

    Leszek Guest

    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>Room:</td></tr>";
    echo"<tr><td>Price:</td></tr>";
    echo"<tr><td>How many rooms?:</td></tr>";

    // data display

    $wynik2=mysql_query($hotel_query2);
    while($wiersz2=mysql_fetch_array($wynik2,MYSQL_NUM))
    {
    echo"<tr><td>".return_data($wiersz2[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
    Leszek, Jan 6, 2006
    #1
    1. Advertising

  2. Leszek wrote:

    > 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::


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

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

    // data display

    $wynik2=mysql_query($hotel_query2);
    while($wiersz2=mysql_fetch_array($wynik2,MYSQL_NUM))
    {
    echo"<tr><td>".return_data($wiersz2[0])."</td>";
    echo"<td >".return_data($wiersz2[1])."</td>";
    echo"<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?


    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
    Beauregard T. Shagnasty, Jan 6, 2006
    #2
    1. Advertising

  3. Leszek

    Leszek Guest

    I want to get this:

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

    But using my code i'm getting:

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

    Pozdrawiam.
    Leszek
    Leszek, Jan 6, 2006
    #3
  4. On Fri, 06 Jan 2006 16:37:02 +0100, Beauregard T. Shagnasty
    <> wrote:

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


    <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 |
    `-------------------------------------------------- --<--@ ------------'
    Barbara de Zoete, Jan 6, 2006
    #4
  5. Leszek

    shagnast Guest

    Barbara de Zoete wrote:
    > On Fri, 06 Jan 2006 16:37:02 +0100, Beauregard T. Shagnasty
    > <> wrote:
    >
    >> Is this what you mean? <tr> starts a new row; you do not want to
    >> put each "column" in its own row.

    >
    > <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>


    You are probably correct. :-0


    echo "<table align=\"center\" width=\"100%\">";
    // data display
    $wynik2=mysql_query($hotel_query2);
    while($wiersz2=mysql_fetch_array($wynik2,MYSQL_NUM))
    {
    echo"<tr><td>Room:</td><td>.return_data($wiersz2[0])."</td></tr>";
    echo"<tr><td>Price:</td><td >".return_data($wiersz2[1])."</td></tr>";
    echo"<tr><td>How 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
    shagnast, Jan 6, 2006
    #5
  6. Leszek wrote:

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


    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>Price</td></tr><tr><td>How
    many?:</td></tr></table>
    </td>
    <td>
    <table><tr><td>return_data($wiersz
    [0])</td></tr><tr><td>return_data($wiersz
    [1])</td></tr><tr><td>return_data($wiersz2[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_data($wiersz2[0]),return_data($wiersz
    [1]),return_data($wiersz2[3]));
    $column[2]=array(return_data($ziersz2[0]),return_data($ziersz
    [1]),return_data($ziersz2[2]));

    echo("<table>");
    for($i=0;$i<=(count($labels)-1);$i++){
    echo("<tr><td>{$labels[$i]}</td>");
    foreach($column AS $col){
    <td>$col[$i]</td>
    }
    echo("</tr>");
    }
    echo("</table>");
    Kevin H. Feeley, Jan 7, 2006
    #6
  7. Leszek

    jukka Guest

    Leszek wrote:
    > 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>Room:</td></tr>";
    > echo"<tr><td>Price:</td></tr>";
    > echo"<tr><td>How many rooms?:</td></tr>";
    >
    > // data display
    >
    > $wynik2=mysql_query($hotel_query2);
    > while($wiersz2=mysql_fetch_array($wynik2,MYSQL_NUM))
    > {
    > echo"<tr><td>".return_data($wiersz2[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
    >
    >

    maybe:

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

    // data display

    $wynik2=mysql_query($hotel_query2);
    while($wiersz2=mysql_fetch_array($wynik2,MYSQL_NUM))
    {
    echo "<tr><td>Room:</td><td>".return_data($wiersz2[0])."</td></tr>";
    echo "<tr><td>Price:</td><td>".return_data($wiersz2[1])."</td></tr>";
    echo "<tr><td>How many
    rooms?:</td><td>".return_data($wiersz2[2])."</td></tr>";
    }
    echo "</table>";
    jukka, Jan 7, 2006
    #7
  8. jukka wrote:

    > maybe:
    >
    > echo " ...


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

    --
    -bts
    -Warning: I brake for lawn deer
    Beauregard T. Shagnasty, Jan 8, 2006
    #8
  9. Leszek

    jukka Guest

    Beauregard T. Shagnasty wrote:
    > jukka wrote:
    >
    >
    >>maybe:
    >>
    >>echo " ...

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

    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|
    jukka, Jan 8, 2006
    #9
  10. jukka wrote:

    > Beauregard T. Shagnasty wrote:
    >> jukka wrote:
    >>
    >>>maybe:
    >>>
    >>>echo " ...

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

    > 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|


    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
    Beauregard T. Shagnasty, Jan 8, 2006
    #10
  11. Leszek

    jukka Guest

    Beauregard T. Shagnasty wrote:
    > jukka wrote:
    >
    >
    >>Beauregard T. Shagnasty wrote:
    >>
    >>>jukka wrote:
    >>>
    >>>
    >>>>maybe:
    >>>>
    >>>>echo " ...
    >>>
    >>>Heh, I believe you "echoed" my code from yesterday. :)
    >>>

    >>
    >>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|

    >
    >
    > 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.
    >

    ah yes, i see it now :)
    jukka, Jan 9, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,096
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Ken Dopierala Jr.

    Do you use <table> or <asp:Table>?

    Ken Dopierala Jr., Jan 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    8,575
    Craig Deelsnyder
    Jan 13, 2004
  3. Earl Teigrob
    Replies:
    2
    Views:
    305
    Shintaro
    Feb 21, 2004
  4. savvy
    Replies:
    1
    Views:
    458
    savvy
    Jan 18, 2006
  5. Rio
    Replies:
    4
    Views:
    1,166
Loading...

Share This Page