Alternating row colors
Posted: Sat Jul 13, 2002 1:18 pm
I have a pretty simple catalog. This catalog displays: products, sizes, UPC, Price, and stock room location. As I have added records to the database I wish to append my view page so that rows will have alternating colors.
I have tried to add the row colors but I am not able to generate anything.
My source code is below:
function make_product_select_row ($which, $value) {
global $db_connection;
echo '<tr><td align="right">Product ' . ucfirst ($which) . ':</td><td align="left"><select name="' . $which . '_id">
';
$tablename = 'product_' . $which . 's';
$columnname = 'product_' . $which . '_id';
$query = "select * from $tablename order by $columnname";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());
while ($row = mysql_fetch_array ($db_query)) {
if ($row[0] == $value) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option value=\"$row[0]\" $selected>$row[1]</option>\n";
}
echo '</select></td></tr>
';
}
function display_products () {
global $db_connection;
echo '<table>
<tr>
<td align="center"><b>SKU</b></td>
<td align="center"><b>Product Name</b></td>
<td align="center"><b>Product Size</b></td>
<td align="center"><b>UPC</b></td>
<td align="center"><b>Price Per Unit</b></td>
<td align="center"><b>Stock Room</b></td>
</tr>
';
$query = "select products.product_id, product_names.product_name AS NAME, product_sizes.product_size AS SIZE, product_formats.product_format AS FORMAT, products.price, products.available from products, product_names, product_sizes, product_formats where products.name_id = product_names.product_name_id and products.size_id = product_sizes.product_size_id and products.format_id = product_formats.product_format_id order by product_id";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());
while ($row = mysql_fetch_array ($db_query)) {
echo " <tr>
<td align=\"center\">$row[product_id]</a></td>
<td align=\"center\">$row[NAME]</td>
<td align=\"center\">$row[SIZE]</td>
<td align=\"center\">$row[FORMAT]</td>
<td align=\"center\">\$$row[price]</td>
<td align=\"center\">$row[available]</td>
</tr>\n";
}
echo '</table>
';
}
Thanks in advance,
-Keith
I have tried to add the row colors but I am not able to generate anything.
My source code is below:
function make_product_select_row ($which, $value) {
global $db_connection;
echo '<tr><td align="right">Product ' . ucfirst ($which) . ':</td><td align="left"><select name="' . $which . '_id">
';
$tablename = 'product_' . $which . 's';
$columnname = 'product_' . $which . '_id';
$query = "select * from $tablename order by $columnname";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());
while ($row = mysql_fetch_array ($db_query)) {
if ($row[0] == $value) {
$selected = 'SELECTED';
} else {
$selected = '';
}
echo "<option value=\"$row[0]\" $selected>$row[1]</option>\n";
}
echo '</select></td></tr>
';
}
function display_products () {
global $db_connection;
echo '<table>
<tr>
<td align="center"><b>SKU</b></td>
<td align="center"><b>Product Name</b></td>
<td align="center"><b>Product Size</b></td>
<td align="center"><b>UPC</b></td>
<td align="center"><b>Price Per Unit</b></td>
<td align="center"><b>Stock Room</b></td>
</tr>
';
$query = "select products.product_id, product_names.product_name AS NAME, product_sizes.product_size AS SIZE, product_formats.product_format AS FORMAT, products.price, products.available from products, product_names, product_sizes, product_formats where products.name_id = product_names.product_name_id and products.size_id = product_sizes.product_size_id and products.format_id = product_formats.product_format_id order by product_id";
$db_query = mysql_query ($query, $db_connection) or die (mysql_error());
while ($row = mysql_fetch_array ($db_query)) {
echo " <tr>
<td align=\"center\">$row[product_id]</a></td>
<td align=\"center\">$row[NAME]</td>
<td align=\"center\">$row[SIZE]</td>
<td align=\"center\">$row[FORMAT]</td>
<td align=\"center\">\$$row[price]</td>
<td align=\"center\">$row[available]</td>
</tr>\n";
}
echo '</table>
';
}
Thanks in advance,
-Keith