murphyz
12-08-2005, 02:54 PM
Hello all,
I'm querying a database and dumping selected information from a db-table into an html table using a function.
This works find and dandy, but there are an extra few columns that I want to add to the table with different information and sums in them.
For example, looking at the code below, I have taken 7 columns of info from the db, and added an extra table header for 'entry fee'. I want this entry fee to be 'played' * 10.
I understand that I can create something such as:
$fee = $played*10;
and then simply add:
echo "<td> $fee </td>";
into the table, but am having trouble with getting the 'played' field as a variable. If this was a normal query I think it would be okay, but I'm having trouble understanding the proper structure of the function.
Could someone please indicate the best way to get all of the fields in the table to work as individual variables so I can use both those and the $row as $data function?
Many thanks
Mxx
<?php
function displaymembers($result)
{
echo "Existing members:";
echo "<table width=\"100%\"><tr bgcolor=\"#FFFFCC\">" .
"<th>Stars ID</th>" .
"<th>Real Name</th>".
"<th>Played</th>".
"<th>Won</th>".
"<th>ITM</th>".
"<th>Lost</th>".
"<th>Payout</th>".
"<th>Entry fee ($)</th>".
"</tr>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=\"center\">";
foreach ($row as $data)
echo "<td> $data </td>";
echo "</tr>";
}
echo "</table>";
}
$query = "SELECT playerid, name, played, won, itm, lost, payout FROM players WHERE include='yes' ORDER BY played DESC";
// open database connection
$connection = mysql_connect("localhost", "dbdata", "dbdata");
mysql_select_db("dbdata", $connection);
$result = mysql_query ("SELECT playerid, name, played, won, itm, lost, payout FROM players WHERE include='yes' ORDER BY played DESC", $connection);
displaymembers($result);
while ($row = mysql_fetch_row($result))
mysql_close($connection);
?>
I'm querying a database and dumping selected information from a db-table into an html table using a function.
This works find and dandy, but there are an extra few columns that I want to add to the table with different information and sums in them.
For example, looking at the code below, I have taken 7 columns of info from the db, and added an extra table header for 'entry fee'. I want this entry fee to be 'played' * 10.
I understand that I can create something such as:
$fee = $played*10;
and then simply add:
echo "<td> $fee </td>";
into the table, but am having trouble with getting the 'played' field as a variable. If this was a normal query I think it would be okay, but I'm having trouble understanding the proper structure of the function.
Could someone please indicate the best way to get all of the fields in the table to work as individual variables so I can use both those and the $row as $data function?
Many thanks
Mxx
<?php
function displaymembers($result)
{
echo "Existing members:";
echo "<table width=\"100%\"><tr bgcolor=\"#FFFFCC\">" .
"<th>Stars ID</th>" .
"<th>Real Name</th>".
"<th>Played</th>".
"<th>Won</th>".
"<th>ITM</th>".
"<th>Lost</th>".
"<th>Payout</th>".
"<th>Entry fee ($)</th>".
"</tr>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=\"center\">";
foreach ($row as $data)
echo "<td> $data </td>";
echo "</tr>";
}
echo "</table>";
}
$query = "SELECT playerid, name, played, won, itm, lost, payout FROM players WHERE include='yes' ORDER BY played DESC";
// open database connection
$connection = mysql_connect("localhost", "dbdata", "dbdata");
mysql_select_db("dbdata", $connection);
$result = mysql_query ("SELECT playerid, name, played, won, itm, lost, payout FROM players WHERE include='yes' ORDER BY played DESC", $connection);
displaymembers($result);
while ($row = mysql_fetch_row($result))
mysql_close($connection);
?>