kartikayg
-
Posts
1 -
Joined
-
Last visited
Never
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Output Data from MYSQL...HELP!!!!
in PHP Coding Help
Posted
Please someone help me...
Here is my code:
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// 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");
$state=$_POST['state'];
$sql="SELECT * FROM $tbl_name WHERE state='$state'";
//$sql = 'SELECT * '
//. ' FROM `nacontact` '
// . ' WHERE 1 AND `state` = \'$stat\'';
$result=mysql_query($sql);
// Define $color=1
$color="1";
while($rows=mysql_fetch_array($result)){
// If $color==1 table row color = #FFC600
if($color==1){ ?>
<tr class="tab_12">
<?php
echo "<td> ".$rows['fname']." ".$rows['lname']."</td>
<td>".$rows['city']."" ?> , <?php echo" ".$rows['state']."</td>
<td>".$rows['email']."</td>
<td>".$rows['phone']."</td>
<td>".$rows['country']."</td>" ?>
</tr>
<?php // Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else { ?>
<tr class="tab_13">
<?php echo "<td>".$rows['fname']." ".$rows['lname']."</td>
<td>".$rows['city']."" ?> , <?php echo" ".$rows['state']."</td>
<td>".$rows['email']."</td>
<td>".$rows['phone']."</td>
<td>".$rows['country']."</td> " ?>
</tr>
<?php
// Set $color back to 1
$color="1";
}
}
mysql_close();
?>