MYSQL PHP Select Order By -


I have the date table of the table, 2 columns as the basis of the data filter - day and day_of_week I query in SQL Day_of_week's day, day_of_week

no problem

  day_of_week day 1 Monday 2 Tuesday 3rd Wednesday 4th Thursday Select different day_off_wec 5 Friday 6 Saturday 7th Sunday  

Then I apply it to the selection box in PHP, so I can choose the value

  $ query = "Separate Day_of_week; day_of_week by date_table command "; $ Res = mysql_query ($ query) or die ("Error in query: $ query." .mysql_error ()); $ Option = ''; {$ ($ Line = mysql_fetch_array ($ res)) {if ($ _ request ["sday"])) {If ($ line ['day_of_week'] == $ _REQUEST ["sday"]) $ option = '& Lt; Option value = "'. $ Line [' day_of_week '].' 'Selected =" selected "& gt;'. $ Line ['day']. ' & Lt; / option & gt; '; Else $ option. =' & Lt; option value = "'. $ Line ['day_of_week']. "& Gt; '. $ Line [' day '].' & Lt; / option & gt; ';} and $ option. =' & Lt; option value = ''. $ Line ['day_of_week']. "" & Gt; '$ Line [' day '].' & Lt; / Option & gt; '; }  

and select box

  & lt; Select name = "sday" class = "sday" & gt; & Lt; Option value = "" & gt; Select Day & lt; / Option & gt; & Lt ;? Php echo $ option; ? & Gt; & Lt; / Select & gt; The end result is something  
  Monday to Friday Saturday Sunday Thursday Tuesday Wednesday   / Code>  
  • Problem 2

    When I select the value "Monday", then all OK. This value passes through "1"

    When I select "Tuesday", it selects value 2,3 and 7. With Wednesday and Sunday only

    Some other selected boxes are made with the same idea, works fine, there is no duplicate of data.

    What could be the problem?

    Do you

      ordering day_of_week asc   

    You want to reorganize your code but such that

      $ selectedString = ($ line ['day_of_week'] == $ _REQUEST ["sday"])? ' Selected ' : ''; & Lt; Option value = "& lt ;? php echo $ row ['day_of_week'] ;? & gt;" & Lt ;? Php echo $ selectStr ;? & Gt; & Gt; & Lt ;? Php echo $ line ['day'] ;? & Gt; & Lt; / Options & gt; ' 

Comments