Tuesday 15 June 2010

mysql - How can I get my data in alphabetic order with PHP -


I'm working on someone else's code and am trying to get data from a list of countries) in alphabetical order.

It should be like this:

  • Company 1 / City A
  • Company 2 / City B
  • Company 3
  • Company B / City D
  • Company A / City D (if in alphabetical order of company names in the same company)
  • Company B / Li> company 7 / city e

    this is my code:

      break; Default: // It's like titles like US $ ret. = '& Lt; Div class = "casino_country_box" & gt; & Lt; One class = "all_contry_link" href = "'. $ Lang.' / Casino / continent / '. Continent.' / All / 1 "& gt; '. L: Open_L () '& lt; / A & gt; & Lt; Div class = "casino_country_box_title" & gt; & Lt; P & gt; '. $ Cont_db ['name_' $ Lang] '& lt; / P & gt; & Lt; / Div & gt; & Lt; Div class = "casino_cuntry_link '; // If this is for the top box in the country ($ this-> Data-> getGet (' all ',' int ')) $ ret. =' Show_all '; / / If "Show All" then companies in all countries should be $ ret. = '' & Show Gt; '; Foreign Currency ($ cont = $ g = & gt; $ v) {// If for every country ($ _GET ['country'] and $ _GET ['country'] == $ v ['id']) $ Ret. = '& Lt; a style = "color: orange; Text-decoration: Underlined! Important; "Href =" '. $ Lang. ' / Casino / continent / '. $ Continent. ' / '. $ V ['id']. "& Gt; ' $ V ['name_' $ Lang] '& lt; / a & gt;' Else {if ($ v ['active'] == 1) // if country is active = link is ACTIVE $ ret. = '& Lt; a href =' '. $ Lang '/ Casino / continent /' $ continent. '/'. $ V ['id'] "$$ ['name_' $ Lang] '& lt; / a & gt;' Else // if country is not active = any active link $ ret. = '& Lt; a href =" Javascript: zero (0) "square =" not_active "> $ V ['name_' $ lang] '& lt; / a & gt;';}} $ ret. = '& Lt; / div & gt; ; & Lt; / div & gt; '; break;;    

    I do not see my city / company array, but an array like city / company -

      $ array = array (array ('company' => 'Google', 'city' = & Gt; 'Dallas'), Array ('Company' '& gt;' Sony ',' City '= & gt;' Albuquerque '), Array (' Company '=>' IBM ',' Every '= & gt;' Dallas '), Array (' Company '=> Array (' Company '=>' Dell '), Array' City '= & gt; El Paso'), Array ( 'Company' = & gt; 'Skype', 'City' = & gt; 'Chicago'));   

    You can use

      foreach ($ = $ $ as $ $ = $ $ line) {$ city [$ key] = $ row ['city']; $ company [$ key] = $ line ['company'];} Array_multisort ($ city, SORT_ASC, $ company, SORT_ASC, $ array); MySort ($ a, $ b) {if ($ a ['city'] == $ b [' City ']) {return strcmp ($ a ["company"], $ b ["company"]); } Other {return strump ($ a ["city"], $ b ["city"]); }} Usort ($ array, 'mySort');   

    Example

    Both array return ( print_r ($ array) )

     Sony [City] = Albuquerque) [1] => Hey ([Company] => Ge [City] = & gt; ;] [2] = & gt; Array ([Company] => Skype [City] => Chicago) [3] => Hey ([Company] => Apple [City] = & Gt; Dallas) [4] = & Gt; Array ([Company] => Google [City] => Dallas) [5] => Hey ([Company] => IBM [City] ] = & Gt; Dallas) [6] = & gt; Array ([Company] => Dell [City] => El Paso))   

    However In your query Rules are always good

      SELECT ... Enck city by order, the company Akshe    

No comments:

Post a Comment