Structure of database "diary":

1--------erik-------- 3--------dec-------something

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:


...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.


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

$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;
| improve this answer | |

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.