SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with checking values with values in MySQL database

    Hello everybody!

    I have a problem. I'm trying to build a discography site. I have MySQL database with 3 tables: disco_albums(aid, name, cover_url, released, producers, additional_info, type['album', 'single', 'video'], cds['1', '2', '3']), disco_songs(lid, aid, song_name, song_length, on_cd['1', '2', '3']) and lyrics(lsid, song_name, song_lyrics). In admin mode, admins can insert new albums. When the album is inserted, admin must select how many cds this album have. and then insert song names. Then PHP inserts song information into disco_songs table. And starts to check if the song already exists in lyrics table. If song already exists with lyrics then album insertion is complete, otherwise redirecting to page where is the <textarea> and admin can insert lyrics. And this is the spot, where my problem is.

    Here's my script:
    PHP Code:

    // get the number of cd-s in album
    $cds $_POST["CD"];

    if(
    $cds == "1") {

         
    $take_last_inserted_id mysql_query("SELECT MAX(aid) FROM disco_albums");
         
    $aid mysql_fetch_row($take_last_inserted_id);
         
    $aid $aid[0];
         
         
    $songs_in_album1 $_POST["songs_in_album1"];

         for(
    $x 0$x $songs_in_album1$x++) {

              
    $song_name1[$x] = $_POST["song_name1"]["$x"];
              
    $song_length1[$x] = $_POST["song_length1"]["$x"];

              
    $insert_cd1 "INSERT INTO disco_songs (aid, song_name, song_length, on_cd) VALUES ('$aid', '$song_name1[$x]', '$song_length1[$x]', '1')";
              
    mysql_query($insert_cd1);

    // from here is the problem

              
    $taking_all_lyrics mysql_query("SELECT * FROM lyrics");
              
    $found mysql_num_rows($taking_all_lyrics);

              if(
    $found != 0) {

                   
    $songs mysql_fetch_array($taking_all_lyrics);
            
                   if (!
    in_array($song_name1[$x], $songs)) {

                        echo 
    "show songs and insert lyrics, which are not in database";

          } else {
                
                        echo 
    "end of inserting album";

          }

               } else {
            
                    echo 
    "table is empty, insert lyrics for all songs";

               }

    // to here

         
    }


    How can I check if those songs already exists in lyrics table?
    If you don't understand something. Please ask...

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Set up select for lyrics

    if (mysql_num_rows($result) == 0) { // no lyrics found
    // do something here
    } else {
    // do something else here
    }
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... Problem now is how can I check exactly which values exists in database and which are not. And then echoing them out to the page. If rows found 0, then no problem: echoing all song names, which admin inserted. But if found more than 0 rows???

  4. #4
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does really anyone can't help me?

  5. #5
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first i am a little tired, so i may do mistakes but fortunately i won't.
    PHP Code:
    if($found != 0) {

                   
    $songs mysql_fetch_array($taking_all_lyrics);
            
                   if (!
    in_array($song_name1[$x], $songs)) {

                        echo 
    "show songs and insert lyrics, which are not in database"
    This is pretty much not all the information you need is it ?

    PHP Code:
    if($found != 0) {

                  while (
    $songs mysql_fetch_array($taking_all_lyrics))
                      {if (
    $songs['song_name']!=$song_name1[$x])
                               {
    redirect stuff ...}
                   echo 
    "show songs and insert lyrics, which are not in database";
                 } 
    well i am not exactly sure bout that, so don't hurt me if its not the thing u needed.
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de

  6. #6
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, we are on the right way. but still slight problem - let's say I insert song1, song2 and song3 to the database and song2 already exists in lyrics table. how can I display song1 and song 3 names in that loop?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •