Page 1 of 1

problem with displaying values

Posted: Sat Oct 23, 2004 6:14 am
by EvilOne
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:

Code: Select all

<?php
// 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 display those values which are'nt in lyrics table?
If you don't understand something. Please ask...

Posted: Mon Oct 25, 2004 11:30 am
by kendall
EvilOne,

To me when you

Code: Select all

mysql_query("SELECT * FROM lyrics");
arent you selecting all the lyrics in the database which maybe like over 100 rows or something?

then if so when you

Code: Select all

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"; 
      }
You probably just searched one array item as

Code: Select all

$songs = mysql_fetch_array($taking_all_lyrics);
just fetches one result
you may want to

Code: Select all

do{  $songs = mysql_fetch_array($taking_all_lyrics);if (!in_array($song_name1[$x], $songs))   }while( $songs = mysql_fetch_array($taking_all_lyrics); )
to loop tru the results to find your match or not match .

i wasnt too shre of the problem though so if i am missing the point do say so

Kendall