When sorting, I have sorted, starting with the first digits, that is 1, 11, 12, 13, 2, 21, 22, but it is necessary that 1, 2, 3, 4 ... 11, 12, etc. Here is my request:

$myCmd = "SELECT * FROM dlpodrazdeleniya, dldoctor, dlSpec, dltime WHERE id='$cat' AND dldoctor.idPodr = dlpodrazdeleniya.idPodr AND dldoctor.SpecID = dlSpec.SpecID AND dldoctor.DoctorID = dltime.DoctorID ORDER BY dltime.Ychastok, dltime.DoctorID"; 

I sort at first by plots, then by doctors, but, more importantly, the plots are sorted, as I described above.

    3 answers 3

    It looks like all, such a result of sorting is due to the fact that the field is text, not digital.

      Naturally this is due to the fact that you are sorting exactly the string! As you know, for this purpose, the sort function is used in the “depths” of SQL (we will call it Compare), which works similarly to the function passed to the qSort sorting function in C ++. It looks something like this (example!):

       int compare(char *a, char *b) { if(a>b) return 1; else if(a<b) return -1; return 0; } 

      This is an approximate operation of the comparison function in C ++ - strcmp() . Here, what results it will give (based on this, draw conclusions):

       "123"<"132" "aabbaa"<"aacwww" // Символ "с">"b"! "bbw122">"bbw121" 

        The easiest option

          ... ORDER BY dltime.Ychastok+1, dltime.DoctorID";