Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi
i started off with a script wich i got working yesterday thanks to the grate people on this net work, now im wanting to have alternationg row colors.
this here workes fine:Code: Select all
<?PHP
//connect to the mysql database
$connection=mysql_connect("localhost","computer_test","test1");
mysql_select_db("computer_price",$connection);
$query="SELECT p.PartNumber, p.Description, (p.IncTax*1.3) AS Price FROM `price list` p";
$data_resource=mysql_query($query,$connection);
//Defining HTML table
$table="<table cellspacing=0 cellpadding=0 border=1 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$table.="<tr>";
$table.="<td>".$row['PartNumber']."</td>";
$table.="<td>".$row['Description']."</td>";
$table.="<td>".$row['Price']."</td>";
$table.="</tr>";
$row_count++;
}
//Closing HTML table
$table.="</table>";
//Displying table and closing mysql database if not need
echo $table;
mysql_close();
?>Code: Select all
$row1 = "#cfdafg";
$row2 = "#ff0000";
$rowcolor = $row1;
while ($myrow = mysql_fetch_array($result)) {
printf'<tr bgcolor="%s"><td>whateverdata</td></tr>', $rowcolor);
if ($rowcolor == $row1) $rowcolor = $row2;
if ($rowcolor == $row2) $rowcolor = $row1;
}Code: Select all
<?PHP
//connect to the mysql database
$connection=mysql_connect("localhost","computer_test","test1");
mysql_select_db("computer_price",$connection);
$query="SELECT p.PartNumber, p.Description, (p.IncTax*1.3) AS Price FROM `price list` p";
$data_resource=mysql_query($query,$connection);
$row1 = "#cfdafg";
$row2 = "#ff0000";
$rowcolor = $row1;
//Defining HTML table
$table="<table cellspacing=0 cellpadding=0 border=1 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$table.="<tr>";
$table.="<tr bgcolor="%s"><td>".$row['PartNumber']."</td></tr>", $rowcolor;
$table.="<tr bgcolor="%s"><td>".$row['Description']."</td>/tr>", $rowcolor;
$table.="<tr bgcolor="%s"><td>".$row['Price']."</td></tr>", $rowcolor;
$table.="</tr>";
if ($rowcolor == $row1) $rowcolor = $row2;
if ($rowcolor == $row2) $rowcolor = $row1;
}
//Closing HTML table
$table.="</table>";
//Displying table and closing mysql database if not need
echo $table;
mysql_close();
?>thanks
clint
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]