Ordering by 2 different field names

Discussion in 'PHP' started by sbaldam1992, Apr 4, 2010.

  1. #1
    Hi
    On my website i want to show a list but i want to order it into different bits with heading. For example (bold is headings)

    Show1
    Series1

    ep1
    ep2
    Series2
    ep1
    ep2

    In the table 'Episode' the field name for the show is 'program' and the name for the series is 'series'
    thanks
    -sbaldam1992
    but the field program is shown as 1 2 or 3 as the way i added then episodes is by selecting from a drop down box. The table this links to is called 'Shows' and yes i have a field called ID to link to it.

    Using php how would i create this?
    If this is confusing tell me and i will try and explain it as my php and mysql knowledge is now that good.

    Thanks in advance
    -sbaldam1992
     
    sbaldam1992, Apr 4, 2010 IP
  2. ChosenOnes.net

    ChosenOnes.net Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I understood you correctly:

    To order by two field names, you use
    ORDER BY field1, field2
    in the mySQL query
     
    ChosenOnes.net, Apr 4, 2010 IP
  3. sbaldam1992

    sbaldam1992 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi yes i have already done this (see source below), but i would like to put it in headers

    (bold is headings)

    Show1
    Series1

    ep1
    ep2
    Series2
    ep1
    ep2

    <?php
    $query = "SELECT * FROM Episode ORDER BY series ASC, episode ASC";
    $query = mysql_query($query) or die(mysql_error());
    while($a = mysql_fetch_assoc($query)){
              echo "<a href=\"/watch.php?id={$a['id']}\">S{$a['series']}, E{$a['episode']} - {$a['name']}</a><br />";
    }
    ?> 
    PHP:
    So the result would be

    Doctor Who
    Series 1

    Rose
    The end of the world
    Series 2
    Tooth and Claw

    Torchwood
    Series 1

    etc.
    Do you know what i mean?
     
    Last edited: Apr 4, 2010
    sbaldam1992, Apr 4, 2010 IP
  4. calcalmx123

    calcalmx123 Well-Known Member

    Messages:
    1,498
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    195
    #4
    All I can say is you need two loop statements but sorry i cant help you with the code.
    I'm still learning :p.

    Thanks,
    Cal.
     
    calcalmx123, Apr 5, 2010 IP
  5. sbaldam1992

    sbaldam1992 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,
    No problem.
    thanks for the info.
     
    sbaldam1992, Apr 5, 2010 IP
  6. gforcecoding

    gforcecoding Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi,
    Correct me if im wrong but from what i can gather you are trying to get them in order using a php query, however i dont think php will allow you to order a query by a none numeric charectar in other words to order it you need the row to be a number not letters.

    Hope this helps.
     
    gforcecoding, Apr 5, 2010 IP
  7. sbaldam1992

    sbaldam1992 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <?php
    $query = "SELECT * FROM Episode ORDER BY series ASC, episode ASC";
    $query = mysql_query($query) or die(mysql_error());
    while($a = mysql_fetch_assoc($query)){
              echo "<a href=\"/watch.php?id={$a['id']}\">S{$a['series']}, E{$a['episode']} - {$a['name']}</a><br />";
    }
    ?> 
    PHP:
    No, using mysql. But all i want to do is put heading on saying the show name, then the series number, and have all the episodes from that show and that series to be in a list.

    Link to the php code above in action
     
    Last edited: Apr 5, 2010
    sbaldam1992, Apr 5, 2010 IP
  8. sbaldam1992

    sbaldam1992 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It seems it won't let me edit my last post.
    but http://ws-fo.co.tv/episodes.php is the layout i want. If there is any way to do this automatically then good. Otherwise i will do it manually
     
    sbaldam1992, Apr 6, 2010 IP