PHP/MySQL sort/arrange from tables -


I am starting to learn some PHP / Mysql and how can I do that I can do this work.

I have all the information on the album (title, release date, cover) on the other track called "Album 2" and on the track I have the name and album id of all the tracks. .

I can fix the selection and capture all the content, but how can I filter by name ALBUM for example and display all the tracks related to that album?

Now I have it

  define ("MYSQLUSER", "root"); Define ("MYSQLPASS", "Root"); Define ("HOSTNAME", "localhost"); Define ("MYSQLDB", "Music"); $ Connection = new mysqli (HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB); If ($ connection-> connect_error) {dead ('Could not connect:'. $ Connection- & gt; connect_error); } Other {$ query = "SELECT *" on a JOINT track as album by T.LLBIM = a.id, by order a.id, t.trackNumber, t.album "; $ Result_obj = ''; $ Result_obj = $ connection- & gt; Query ($ query); While ($ result = $ result_obj-> fetch_arrow (MYSQLI_ASSOC)) {$ item [] = $ result; } Forex ($ item $ item) {echo "
  • UL>
  • "; Echo $ item ['name']; Resonate "-" echo $ item ['file']; Echo " "; }

    The problem is that all the albums / tracks will output separately from each other.

    Like it:

      & lt; Ul & gt; & Lt; Li & gt; Album 1 - File 1 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; Ul & gt; & Lt; Li & gt; Album 1 - File 2 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; Ul & gt; & Lt; Li & gt; Album 2 - File 1 & lt; / Li & gt; & Lt; / Ul & gt;   

    How can I create an album on the same ul / li tag? I know my foreach is loop. But what can I do?

    Then it will be:

      & lt; Ul & gt; & Lt; Li & gt; Album 1 - File 1, Album 1 - File 2, Album 1 - File 3 & lt; / Li & gt; & Lt; Li & gt; Album 2 - File 1 & lt; / Li & gt; & Lt; / Ul & gt;   

    thanks

    You can leave the query because of the bus Improve the loop in the form:

      "; $ First = true; $ Previous_album = ''; While ($ result = $ result_obj-> fetch_array (MYSQLI_ASSOC)) {if ($ previous_album! = $ Result ['album']) {$ previous_album = $ result ['album']; If (! $ Before) {echo ""; } And {$ first = false; } Echo "
    • "; } Else {echo ","; } Resonance $ result ['name']; Echo "-"; Resonance $ result ['file']; } Echo " ";

      Also keep in mind that I am doing everything in just one loop, now you are using two loops (to get rows from DB to display another result ) I'm doing everything in just one loop, which will increase your app's performance.

      Tell me if you need further help by fadex

  • Comments