Mysql – Query distinct then select option then choose and query choosed as html result on page

MySQLPHP

Structure of database "diary":

id------user_name-----day-----month------post
1--------erik-------- 3--------dec-------something
1--------erik---------3--------dec-------12345
1--------erik---------2--------dec-------kkkkk
1--------erik---------6--------jan-------ok
2--------john---------1---------dec------testing

Now I need to get unique month for user $login_session and show him select option. I managed to get distinct select option query from the database.
So here it is, and it's working:

$sql = "SELECT DISTINCT  month FROM `diary` 
    where user_name = '$login_session' order by month"; 
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result)){
    echo '<option value="'.$row['month'].'">'.$row['month'].'</option>';
}

When user erik login he got:

dec
jan

…as option. The problem is when user login and see top option value on select to list his data. Example:

Let's say he choose dec, I need to get his output in html form:

 id----day ------- month ------- posts ------------
  1----3 ------- dec -------  something  ------- 
  1----3 ------- dec -------  12345 ------- 
  1----2 ------- dec -------  kkkkk  ------- 

Basically, I am trying to list logged user all posts by month select.

Best Answer

I manage to solve the problem, here is the code for others who need help.

$sid=$_GET['month'];
$sql = "SELECT * FROM diary where user_name = '$login_session' 
    and month= '$sid' ORDER BY day";
$result = mysql_query($sql);
while ($rs=mysql_fetch_object($result)){

and then just wrap in tables:

echo $rs->day;
echo $rs->post;
}