<html>
<body>
<!-- sample body -->
<?php
// sample connection string for your database access
$hostname = "localhost";
$database = "sample_country_database";
$username = "root";
$password = "samplepassword";
mysql_connect($hostname,$username,$password);
mysql_select_db($database) or die("Unable to select database.");
?>
<!-- select field and query -->
<form method="post">
<br>
<select name="thecountryname" width = "200">
<option value=''> Country Names </option>
<!-- sample country names display -->
<?php
$myquery=mysql_query("SELECT DISTINCT sample_country_name
from sample_country_table
");
if(mysql_fetch_object($myquery) == null)
{
echo "<option value=''> No Record Found. </option>";
}
else
{
$myquery=mysql_query("SELECT DISTINCT sample_country_name
from sample_country_table
");
while($countryname=mysql_fetch_object($myquery))
{
echo "<option value='$countryname->sample_country_name'>".$countryname->sample_country_name."</option>";
}
}
?>
</select>
<input type="submit" name="view" value=" View ">
</form>
<?php
if($_POST['view'])
{
$counname = $_POST['thecountryname'];
if($counname == null)
{
echo "<script type='text/javascript'>window.alert('Please check your input.')</script>";
//echo "<META http-equiv='refresh' content='0; URL=index.php'>";
}
else if($counname != null)
{
$myquery=mysql_query("SELECT * from sample_coutry_table");
if(mysql_fetch_object($myquery) == null)
{
echo "<center>No Record Found.</center>"; // ---> this is if the sample_country_table have no values
}
else
{
$myquery=mysql_query("SELECT DISTINCT sample_coutry_name
from sample_country_table
where sample_coutry_name = '$counname'
");
while($x=mysql_fetch_object($myquery))
{
echo " <center> ";
echo " <font color = 'red'>Coutry Name : </font>".$x->sample_coutry_name;
}
echo "
<br>
<center>
<table class = sample align=center width=1350px height = 50>
<tr bgcolor = '#82CAFA'>
<td width='50' align = 'center'> - </center></td>
<td width='250' align = 'center'>COUTRY NAME</center></td>
<td width='50'><center>COUNTRY DETAIL 1</center></td> <!-- sample details from here -->
<td width='50'><center>COUNTRY DETAIL 2</center></td>
<td width='50'><center>COUNTRY DETAIL 3</center></td>
</tr><tr></tr>";
$myquery=mysql_query("SELECT sample_country_name, detail1, detail2, detail3
from sample_coutry_table
where sample_country_name like '$counname'
order by sample_country_name");
$check=0;
while($y=mysql_fetch_object($myquery))
{
$check++;
//---- country name ----
echo "<tr>";
echo "<td align = right width='50'>$check</td>";
echo "<td width='250' align = left>".$y->sample_country_name."</td>";
if ($y->detail1 == 0 || $y->detail1 == null) // ---> sample details and column names from here
{
echo "<td width='50' align = center><font color = red>"." - "."</font></td>";
}
else
{
echo "<td width='50' align = center>".$y->detail1."</td>";
}
if ($y->detail2 == 0 || $y->detail2 == null)
{
echo "<td width='50' align = center>"." - "."</td>";
}
else
{
echo "<td width='50' align = center>".$y->detail2."</td>";
}
if ($y->detail3 == 0 || $y->detail3== null)
{
echo "<td width='50' align = center>"." - "."</td>";
}
else
{
echo "<td width='50' align = center>".$y->detail3."</td>";
}
echo "</tr>";
}
echo "<tr></tr><tr></tr>";
echo "</table></center><br>";
echo " <br>";
}
}
else
{
echo "<center>No Record Found.</center>";
}
}
else
{
echo "<center>No Record Found.</center>";
}
?>
</body>
</html>