Hi ppl,

In a drop down box in PHP i want a distinct value of Date from a column in mysql table.

W_Id  FinishedDate  Username
1         2010-01-25     me
2         2010-01-25     you
3         2010-01-25    she
4        2010-01-26      me
5         2010-01-26     you
6         2010-01-26     she

In the dropdown box i want 2010-01-25 and 2010-01-26 to be displayed only once.

But when I select the date (eg:2010-01-25) in the drop down box, in the next step i want

W_Id  FinishedDate  Username
1         2010-01-25     me
2         2010-01-25     you
3         2010-01-25    she

My PHP code for Drop down box:(I think there is some mistake in this code). I have used Ajax to display on the same screen::

$sql="SELECT DISTINCT(FinishedDate), W_Id FROM WD WHERE Project_Id= '$Project_Id' ORDER BY FinishedDate";

$result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());

echo "<select name=date value=' ' onChange=showDetails(this.value)>Date</option>";
echo "<option>select Date</option>";

while($row = mysql_fetch_array($result))
  {
      echo "<OPTION VALUE=$row[W_Id]>$row[FinishedDate]</option>";
  }

echo "</select>";

Code for displaying the details when selected a date:

$sql="SELECT * FROM WD WHERE W_Id='".$W_Id."'";

$result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());

echo "<table border='1'>
<tr>
<th>Username</th>
<th>W_Id</th>
<th>FinishedDate</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
echo"<tr>";
  echo "<td>".$row['Username']."</td>"; 
  echo "<td>".$row['W_Id']."</td>";
  echo "<td>".$row['FinishedDate']."</td>";
 
echo "</tr>";
  }

HELP!!!
Thank you in advance

Recommended Answers

All 12 Replies

It's difficult to give you a right answer to the question. But u can look to php tutorials

Member Avatar for diafol

OH you yukky pup - put some quotes on! The last time I saw naked attribute values I nearly died of fright!

Hi Himanshi,

I cannot pay for the work, if that is what you are expecting.

Hello
I read your mail and thank you for replying and i will see if ther is any help i can do for you.

try GROUP BY in select query. example see herelink . it helps you.

Hi raja,

I tried GROUP BY, it didn't work.
Group by displays only one row.
Thanx

try GROUP BY in select query. example see herelink . it helps you.

Please try this .....

Please try this .....

$sql="SELECT DISTINCT FinishedDate FROM WD WHERE Project_Id= '".$Project_Id."' ORDER BY FinishedDate";

$result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());

echo "<select name='your_selected_date'  onChange=showDetails(this.value)>Date</option>";
echo "<option>select Date</option>";

while($row = mysql_fetch_array($result))
  {
	  
      echo "<OPTION VALUE='".$row[FinishedDate]."'>".$row[FinishedDate]."</option>";
	  
  }//EO while($row = mysql_fetch_array($result))

echo "</select>";

~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*


Code for displaying the details when selected a date:

$sql="SELECT * FROM WD WHERE FinishedDate='".$your_selected_date."' order by  FinishedDate asc";

$result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());

echo "<table border='1'>
<tr>
	<th>Username</th>
	<th>W_Id</th>
	<th>FinishedDate</th>
</tr>";

if(mysql_num_rows($result) > 0)
{
	
	while($row = mysql_fetch_array($result))
	  {
		  
		echo"<tr>";
		  
			echo "<td>".$row['Username']."</td>"; 
			echo "<td>".$row['W_Id']."</td>";
			echo "<td>".$row['FinishedDate']."</td>";	 
		  
		echo "</tr>";
		  
	  }//EO while($row = mysql_fetch_array($result))
	  
}//EO if(mysql_num_rows($result) > 0)
$sql="SELECT FinishedDate, W_Id FROM WD WHERE Project_Id= '$Project_Id' GROUP BY FinishedDate";
       
      $result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());
       
      echo "<select name=date value=' ' onChange=showDetails(this.value)>Date</option>";
      echo "<option>select Date</option>";
       
      while($row = mysql_fetch_array($result))
      {
      echo "<OPTION VALUE=$row[FinishedDate]>$row[FinishedDate]</option>";
      }
       
      echo "</select>";
$sql="SELECT * FROM WD WHERE FinishedDate='".$FinishedDate."' order by  W_Id asc";

      $result = mysql_query($sql) or die("Query to get info ended in error:".mysql_error());
       
     echo "<table border='1'>
       <tr>
      <th>Username</th>
      <th>W_Id</th>
      <th>FinishedDate</th>
      </tr>";
       
      while($row = mysql_fetch_array($result))
      {
      echo"<tr>";
      echo "<td>".$row['Username']."</td>";
      echo "<td>".$row['W_Id']."</td>";
      echo "<td>".$row['FinishedDate']."</td>";
       
      echo "</tr>";
      }

try above code.

Hi Manish,

WOW!!! That worked Great!!!!

But I have another Problem...

This is the Table:

W_Id  FinishedDate  Username
  1        2010-01-25     me
  2        2010-01-25     you
  3       2010-01-26      me
  4       2010-01-26     you

In the First Dropdown box, I have the list of Username: me, you

In the second Dropdown box, I have the FinishedDate corresponding to the users...
ie: When i click (me) in first DDbox, I will get 2010-01-25 and 2010-01-26 in the second drop down box...

NOW, When i select the date (eg:2010-01-25)
I want the entire row related to (me and 2010-01-25) to be displayed, like this:

W_Id    Username   FinishedDate
 1              me            2010-01-25

I have used AJAX so that it will be displayed on the same page...
My problem is i don't know how to pass both the variable of Username and FinishedDate in the AJAX Function

function showDetails(Username, FinishedDate)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getdetails3.php";
url=url+"?FinishedDate="+FinishedDate ;
url=url+"&Username="+Username;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

Do u have an idea, how to solve this???
Thanx

Hi,

Thankyou very much!!!!

I solved the problem.... I GOT ITTTT

I couldn't have done it without your help

Thanx a million

You are welcome...

Hi,

Thankyou very much!!!!

I solved the problem.... I GOT ITTTT

I couldn't have done it without your help

Thanx a million

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.