0

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.

0

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.