Logo 
Search:

PHP Forum

Ask Question   UnAnswered
Home » Forum » PHP       RSS Feeds

retrieve different data by using select option

  Asked By: Anonymous    Date: Apr 28    Category: PHP    Views: 1046
  

I tried to show different data in table when the user choose different option from the first page...and I tried to give sort function using javascript..however, the shown data is same even though the user chose different option...
I think there are some logic error which I'm not noticed it

this is my code

<?php
$connect = mysql_connect("localhost", "root", "");

//connect to database
//select the database
mysql_select_db("fak_databases");
//submit button
if($_POST['formSubmit'] == "Submit")
{
$country = $_POST['country'];
}

if(isset($_GET['orderby'])){
$order = $_GET['orderby'];
$sort = $_GET['sort'];

if($country == TRUE) {
// query to get all US records
if($order != 'wipo_applicant1_city' && $order != 'applicant1_addr1' && $order != 'wipo_applicant1_state')$order = "wipo_applicant1_city";
if($sort != 'asc' && $sort != 'desc')$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1, wipo_applicant1_state, `invention-title` FROM auip_wipo_sample WHERE applicant1_country= '$country' ORDER BY ".mysql_real_escape_string($order)." ".$sort;

//here we reverse the sort variable
if($sort == "asc"){
$sort = "desc";
}
else{
$sort = "asc";
}

}
}else {
$order = "";
$sort = "asc";
$sql = "SELECT * FROM `auip_wipo_sample`";
}
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$row_counter = 0;

$icon = "";
echo "<table border=\"1\" cellspacing=\"0\">\n";
echo "<tr>\n";

// first column
echo "<th>";
$icon = "";
if($order == "wipo_applicant1_city"){
if($sort == "asc"){
$icon = "<img src=\"images/up.png\" class=\"arrowSpace\"/>";
}
if($sort == "desc"){
$icon = "<img src=\"images/down.png\" class=\"arrowSpace\"/>";
}
}

//print the result
echo "<a href='index2.php?orderby=wipo_applicant1_city&sort=".$sort."'>City</a>".$icon;
echo "</th>\n";


// second column
echo "<th>";
$icon = "";
if($order == "applicant1_addr1"){
if($sort == "asc"){
$icon = "<img src=\"images/up.png\" class=\"arrowSpace\"/>";
}
if($sort == "desc"){
$icon = "<img src=\"images/down.png\" class=\"arrowSpace\"/>";
}
}
echo "<a href='index2.php?orderby=applicant1_addr1&sort=".$sort."'>Address</a>".$icon;
echo "</th>\n";


// third column
echo "<th>";
$icon = "";
if($order == "wipo_applicant1_state"){
if($sort == "asc"){
$icon = "<img src=\"images/up.png\" class=\"arrowSpace\"/>";
}
if($sort == "desc"){
$icon = "<img src=\"images/down.png\" class=\"arrowSpace\"/>";
}
}
echo "<a href='index2.php?orderby=wipo_applicant1_state&sort=".$sort."'>State</a>".$icon;
echo "</th>\n";
echo "</tr>";

//fetch the result
while($row = mysql_fetch_array($result)){

//give a different color for row
if($row_counter % 2){
$row_color="bgcolor='#FFFFFF'";
}else{
$row_color="bgcolor='#F3F6F8'";
}
echo "<tr class=\"TrColor\" ".$row_color.">";
echo "<td>" . $row['wipo_applicant1_city'] . "</td>\n";
echo "<td>" . $row['applicant1_addr1'] . "</td>\n";
echo "<td>" . $row['wipo_applicant1_state'] . "</td>\n";
echo "</tr>";
$row_counter++;
}
echo "</table>";
?>

anyone know the error???

Share: 

 

1 Answer Found

 
Didn't find what you were looking for? Find more on retrieve different data by using select option Or get search suggestion and latest updates.




Tagged: