hyperlink list from database columns












0















I have a mysql database with my movies



id | movietitle | year | imdbnumber


I want to display my movies as a hyperlink list with a php sql query



like this



<a href="http://www.imdb.com/title/ttIMDBNUMBER/" target="_blank">MOVIETITLE (YEAR)</a><br>


i want them sorted and grouped by letter



Example:



T
Titanic (1997)
THX 1138 (1971)

U
Underworld (2003)
...


how can I do that in php?










share|improve this question




















  • 1





    what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

    – rlatief
    Feb 17 '13 at 6:15











  • php.net/manual/en/book.pdo.php

    – Jon
    Feb 17 '13 at 6:15











  • MySQLi might be easier initially. Then PDO.

    – Achrome
    Feb 17 '13 at 6:19






  • 1





    Haha, ok, then: php.net/manual/en/book.mysqli.php

    – Jon
    Feb 17 '13 at 6:20
















0















I have a mysql database with my movies



id | movietitle | year | imdbnumber


I want to display my movies as a hyperlink list with a php sql query



like this



<a href="http://www.imdb.com/title/ttIMDBNUMBER/" target="_blank">MOVIETITLE (YEAR)</a><br>


i want them sorted and grouped by letter



Example:



T
Titanic (1997)
THX 1138 (1971)

U
Underworld (2003)
...


how can I do that in php?










share|improve this question




















  • 1





    what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

    – rlatief
    Feb 17 '13 at 6:15











  • php.net/manual/en/book.pdo.php

    – Jon
    Feb 17 '13 at 6:15











  • MySQLi might be easier initially. Then PDO.

    – Achrome
    Feb 17 '13 at 6:19






  • 1





    Haha, ok, then: php.net/manual/en/book.mysqli.php

    – Jon
    Feb 17 '13 at 6:20














0












0








0








I have a mysql database with my movies



id | movietitle | year | imdbnumber


I want to display my movies as a hyperlink list with a php sql query



like this



<a href="http://www.imdb.com/title/ttIMDBNUMBER/" target="_blank">MOVIETITLE (YEAR)</a><br>


i want them sorted and grouped by letter



Example:



T
Titanic (1997)
THX 1138 (1971)

U
Underworld (2003)
...


how can I do that in php?










share|improve this question
















I have a mysql database with my movies



id | movietitle | year | imdbnumber


I want to display my movies as a hyperlink list with a php sql query



like this



<a href="http://www.imdb.com/title/ttIMDBNUMBER/" target="_blank">MOVIETITLE (YEAR)</a><br>


i want them sorted and grouped by letter



Example:



T
Titanic (1997)
THX 1138 (1971)

U
Underworld (2003)
...


how can I do that in php?







php html mysql hyperlink






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:09









Cœur

17.6k9105145




17.6k9105145










asked Feb 17 '13 at 6:12









user2079829user2079829

1




1








  • 1





    what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

    – rlatief
    Feb 17 '13 at 6:15











  • php.net/manual/en/book.pdo.php

    – Jon
    Feb 17 '13 at 6:15











  • MySQLi might be easier initially. Then PDO.

    – Achrome
    Feb 17 '13 at 6:19






  • 1





    Haha, ok, then: php.net/manual/en/book.mysqli.php

    – Jon
    Feb 17 '13 at 6:20














  • 1





    what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

    – rlatief
    Feb 17 '13 at 6:15











  • php.net/manual/en/book.pdo.php

    – Jon
    Feb 17 '13 at 6:15











  • MySQLi might be easier initially. Then PDO.

    – Achrome
    Feb 17 '13 at 6:19






  • 1





    Haha, ok, then: php.net/manual/en/book.mysqli.php

    – Jon
    Feb 17 '13 at 6:20








1




1





what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

– rlatief
Feb 17 '13 at 6:15





what have you tried / what's your PHP level (have no clue, beginner, intermediate, etc.)?

– rlatief
Feb 17 '13 at 6:15













php.net/manual/en/book.pdo.php

– Jon
Feb 17 '13 at 6:15





php.net/manual/en/book.pdo.php

– Jon
Feb 17 '13 at 6:15













MySQLi might be easier initially. Then PDO.

– Achrome
Feb 17 '13 at 6:19





MySQLi might be easier initially. Then PDO.

– Achrome
Feb 17 '13 at 6:19




1




1





Haha, ok, then: php.net/manual/en/book.mysqli.php

– Jon
Feb 17 '13 at 6:20





Haha, ok, then: php.net/manual/en/book.mysqli.php

– Jon
Feb 17 '13 at 6:20












2 Answers
2






active

oldest

votes


















0














You can sort the list using the SQL query itself using ORDER BY.



Once you have the data out of the DB, you can create each of the hyperlinks like this:



<a href="http://www.imdb.com/title/tt<?=$imdbnumber?>/" target="_blank"><?=$movietitle?> <?=$year?></a><br>





share|improve this answer































    0














    If you don't want to use regular expressions, this is one of the solutions.



    <?php
    $movie[0]='Amber';
    $movie[1]='babar';
    $movie[2]='Aviator';
    $movie[3]='Caty boy';

    function startsWith($haystack, $needle)
    {
    return !strncmp($haystack, $needle, strlen($needle));
    }

    foreach (range('a', 'z') as $i){
    echo '<h1>'.strtoupper($i).'</h1>';
    foreach($movie as $key){
    if(startsWith(strtolower($key),$i)){
    echo '<li>'.$key.'</li>';
    }
    }
    }


    ?>


    Output for above would be :



    A
    Amber
    Aviator
    B
    Babar
    C
    Caty boy
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    Z


    Populate your $movie array from the database of course with ORDER BY SQL query. Then $movie array can be in this format



    Title - (Year)


    It won't make a difference what you put after the title - year or any other detail. The condition is that your string should start with the title. SO even if you miss out the format, Ex:



    $movie[0]='Titanic';
    $movie[1]='Hulk (2009)';


    still the function should sort it in the manner you described in your problem statement. Hope it helps.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14918509%2fhyperlink-list-from-database-columns%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You can sort the list using the SQL query itself using ORDER BY.



      Once you have the data out of the DB, you can create each of the hyperlinks like this:



      <a href="http://www.imdb.com/title/tt<?=$imdbnumber?>/" target="_blank"><?=$movietitle?> <?=$year?></a><br>





      share|improve this answer




























        0














        You can sort the list using the SQL query itself using ORDER BY.



        Once you have the data out of the DB, you can create each of the hyperlinks like this:



        <a href="http://www.imdb.com/title/tt<?=$imdbnumber?>/" target="_blank"><?=$movietitle?> <?=$year?></a><br>





        share|improve this answer


























          0












          0








          0







          You can sort the list using the SQL query itself using ORDER BY.



          Once you have the data out of the DB, you can create each of the hyperlinks like this:



          <a href="http://www.imdb.com/title/tt<?=$imdbnumber?>/" target="_blank"><?=$movietitle?> <?=$year?></a><br>





          share|improve this answer













          You can sort the list using the SQL query itself using ORDER BY.



          Once you have the data out of the DB, you can create each of the hyperlinks like this:



          <a href="http://www.imdb.com/title/tt<?=$imdbnumber?>/" target="_blank"><?=$movietitle?> <?=$year?></a><br>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 17 '13 at 6:20









          ATOzTOAATOzTOA

          19.4k166699




          19.4k166699

























              0














              If you don't want to use regular expressions, this is one of the solutions.



              <?php
              $movie[0]='Amber';
              $movie[1]='babar';
              $movie[2]='Aviator';
              $movie[3]='Caty boy';

              function startsWith($haystack, $needle)
              {
              return !strncmp($haystack, $needle, strlen($needle));
              }

              foreach (range('a', 'z') as $i){
              echo '<h1>'.strtoupper($i).'</h1>';
              foreach($movie as $key){
              if(startsWith(strtolower($key),$i)){
              echo '<li>'.$key.'</li>';
              }
              }
              }


              ?>


              Output for above would be :



              A
              Amber
              Aviator
              B
              Babar
              C
              Caty boy
              D
              E
              F
              G
              H
              I
              J
              K
              L
              M
              N
              O
              P
              Q
              R
              S
              T
              U
              V
              W
              X
              Y
              Z


              Populate your $movie array from the database of course with ORDER BY SQL query. Then $movie array can be in this format



              Title - (Year)


              It won't make a difference what you put after the title - year or any other detail. The condition is that your string should start with the title. SO even if you miss out the format, Ex:



              $movie[0]='Titanic';
              $movie[1]='Hulk (2009)';


              still the function should sort it in the manner you described in your problem statement. Hope it helps.






              share|improve this answer






























                0














                If you don't want to use regular expressions, this is one of the solutions.



                <?php
                $movie[0]='Amber';
                $movie[1]='babar';
                $movie[2]='Aviator';
                $movie[3]='Caty boy';

                function startsWith($haystack, $needle)
                {
                return !strncmp($haystack, $needle, strlen($needle));
                }

                foreach (range('a', 'z') as $i){
                echo '<h1>'.strtoupper($i).'</h1>';
                foreach($movie as $key){
                if(startsWith(strtolower($key),$i)){
                echo '<li>'.$key.'</li>';
                }
                }
                }


                ?>


                Output for above would be :



                A
                Amber
                Aviator
                B
                Babar
                C
                Caty boy
                D
                E
                F
                G
                H
                I
                J
                K
                L
                M
                N
                O
                P
                Q
                R
                S
                T
                U
                V
                W
                X
                Y
                Z


                Populate your $movie array from the database of course with ORDER BY SQL query. Then $movie array can be in this format



                Title - (Year)


                It won't make a difference what you put after the title - year or any other detail. The condition is that your string should start with the title. SO even if you miss out the format, Ex:



                $movie[0]='Titanic';
                $movie[1]='Hulk (2009)';


                still the function should sort it in the manner you described in your problem statement. Hope it helps.






                share|improve this answer




























                  0












                  0








                  0







                  If you don't want to use regular expressions, this is one of the solutions.



                  <?php
                  $movie[0]='Amber';
                  $movie[1]='babar';
                  $movie[2]='Aviator';
                  $movie[3]='Caty boy';

                  function startsWith($haystack, $needle)
                  {
                  return !strncmp($haystack, $needle, strlen($needle));
                  }

                  foreach (range('a', 'z') as $i){
                  echo '<h1>'.strtoupper($i).'</h1>';
                  foreach($movie as $key){
                  if(startsWith(strtolower($key),$i)){
                  echo '<li>'.$key.'</li>';
                  }
                  }
                  }


                  ?>


                  Output for above would be :



                  A
                  Amber
                  Aviator
                  B
                  Babar
                  C
                  Caty boy
                  D
                  E
                  F
                  G
                  H
                  I
                  J
                  K
                  L
                  M
                  N
                  O
                  P
                  Q
                  R
                  S
                  T
                  U
                  V
                  W
                  X
                  Y
                  Z


                  Populate your $movie array from the database of course with ORDER BY SQL query. Then $movie array can be in this format



                  Title - (Year)


                  It won't make a difference what you put after the title - year or any other detail. The condition is that your string should start with the title. SO even if you miss out the format, Ex:



                  $movie[0]='Titanic';
                  $movie[1]='Hulk (2009)';


                  still the function should sort it in the manner you described in your problem statement. Hope it helps.






                  share|improve this answer















                  If you don't want to use regular expressions, this is one of the solutions.



                  <?php
                  $movie[0]='Amber';
                  $movie[1]='babar';
                  $movie[2]='Aviator';
                  $movie[3]='Caty boy';

                  function startsWith($haystack, $needle)
                  {
                  return !strncmp($haystack, $needle, strlen($needle));
                  }

                  foreach (range('a', 'z') as $i){
                  echo '<h1>'.strtoupper($i).'</h1>';
                  foreach($movie as $key){
                  if(startsWith(strtolower($key),$i)){
                  echo '<li>'.$key.'</li>';
                  }
                  }
                  }


                  ?>


                  Output for above would be :



                  A
                  Amber
                  Aviator
                  B
                  Babar
                  C
                  Caty boy
                  D
                  E
                  F
                  G
                  H
                  I
                  J
                  K
                  L
                  M
                  N
                  O
                  P
                  Q
                  R
                  S
                  T
                  U
                  V
                  W
                  X
                  Y
                  Z


                  Populate your $movie array from the database of course with ORDER BY SQL query. Then $movie array can be in this format



                  Title - (Year)


                  It won't make a difference what you put after the title - year or any other detail. The condition is that your string should start with the title. SO even if you miss out the format, Ex:



                  $movie[0]='Titanic';
                  $movie[1]='Hulk (2009)';


                  still the function should sort it in the manner you described in your problem statement. Hope it helps.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 17 '13 at 8:48

























                  answered Feb 17 '13 at 6:36









                  harsh8888harsh8888

                  422821




                  422821






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14918509%2fhyperlink-list-from-database-columns%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Error while running script in elastic search , gateway timeout

                      Adding quotations to stringified JSON object values