I have this code:
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY cat ASC";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><form name="form1" method="post" action="">
<table width="500" border="1" cellpadding="2" cellspacing="0" bgcolor="#CCCCCC" align="center">
<tr>
<td bgcolor="#FFFFFF" width="30"><font face='verdana'><font size='2'><strong>Delete</strong></td>
<td bgcolor="#FFFFFF"><font face='verdana'><font size='2'><strong>URL</strong></td>
<td bgcolor="#FFFFFF" width="50"><font face='verdana'><font size='2'><strong>Category</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF" width="30"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><font face='verdana'><font size='1'><a target="_blank" href="<?php echo $rows['url']; ?>"><?php echo $rows['name']; ?></a>
<td bgcolor="#FFFFFF" width="50"><font face='verdana'><font size='1'><? echo $rows['cat']; ?></td>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
}
mysql_close();
?>
I'm trying to integrate this code that alternates the colors:
<?php
// Displays alternate table row colors
function row_color($i){
$bg1 = "#cccccc"; // color one
$bg2 = "#ffffff"; // color two
if ( $i%2 ) {
return $bg1;
} else {
return $bg2;
}
}
//DB connection
$connection = mysql_connect("localhost","userName","password");
$db = mysql_select_db("databaseName");
$sql = "select * from tbl_name"; // Database Query
$result = mysql_query("$sql"); // Database Query result
// Starts the table
echo "<table bgcolor=#FFFFFF border=0 cellpadding=1 cellspacing=1>\n";
// Create the contents of the table.
for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){
echo "<TR>\n"
."<TD bgcolor=".row_color($i).">".$row["name"]."</TD>\n"
."<TD bgcolor=".row_color($i).">".$row["url"]."</TD>\n"
."<TD bgcolor=".row_color($i).">".$row["cat"]."</TD>\n"
."</TR>";
}
echo "</TABLE>"
?>
I've tried every way but the right way to do this apparently. The alternating code works I just can't figure out how to get it in my other file. Can some help please?