Problem with table...

L

Leszek

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
 
B

Beauregard T. Shagnasty

Leszek said:
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 said:
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.
 
L

Leszek

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
 
B

Barbara de Zoete

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 |
`-------------------------------------------------- --<--@ ------------'
 
S

shagnast

Barbara said:
<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.
 
K

Kevin H. Feeley

Leszek said:
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>");
 
J

jukka

Leszek said:
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>";
 
J

jukka

Beauregard said:
jukka wrote:




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

Beauregard T. Shagnasty

jukka said:
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.
 
J

jukka

Beauregard said:
jukka wrote:




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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top