Forum Moderators: coopster & phranque

Message Too Old, No Replies

formatting data

         

aline

10:57 pm on Apr 27, 2003 (gmt 0)

10+ Year Member



I want to query a database and put the result in a table.
the result of the query is held in an array @result.
I'd like to present the information in a table for better viewing. For example if in the array from the query I have all the locomotives a trainspotter has seen with the date I'd like to have a column with all the locomotives name and a column with the dates. If I do the following:

while(@result=$s->fetchrow())

{for($index=0;$index<@result;$index++)
{
print "<tr><td>$result[$index]</td></tr>";

}

all the data go in a different row, which is not what I want.

I I do {
print "<tr><td align=center>@vresult</td></tr>";
print"\t";
}

the result is better but it is not perefect as it only creates one column and not two which I'd like so that some heading could be added.

Could anyone help?
Thanks
}

all the

DrDoc

11:02 pm on Apr 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you want all the results in two columns, or each result split over two columns?

bonanza

11:08 pm on Apr 27, 2003 (gmt 0)



You probably want something more like this, no?


while(@result=$s->fetchrow()) {
print "<tr>";
for($index=0;$index<@result;$index++) {
print "<td>$result[$index]</td>";
}
print "</tr>";
}

aline

11:32 pm on Apr 27, 2003 (gmt 0)

10+ Year Member



I've just tried this but it still appears as:

locomotive name sighting date in one column instead of locomotive name in one column and sighting date in another!

willybfriendly

3:46 am on Apr 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$num_results = mysql_num_rows($result);

for($i=0; $i <$num_results; $i++)
{
$train = mysql_fetch_array($result);
echo "<TR><TD>$train[locomotive]</TD>";
echo "<TD>$train[sightings]</TD></TR>";
}

Is that what you are looking for?

WBF

aline

9:37 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



It's working now! Thank you very much!