Search Database using information from flat file
Posted: Sun Jan 16, 2011 5:42 pm
In a nut shell this script reads a filename/path out of a flat text file and then searchs the database and matchs it up with the artist and genre and title stored on the database. then prints them in order by the line of the flat file and displays the number next to each result.. but this script is slow do to the fact that for each line in the flat file it reads it then querys the database. this flat file can contain 100+ results that it need to search the database for. i want it to list them all in order without using a tag in the database i want it to be in order by the order of the flat file and display a line number for each result.. please help this script does everything i need but its slow to repeated mysqli_query
Thanks
require('dbconfig1.php'); // connect to database
$bad_symbols = array("'",","); // set bad symbols
$linesgood = str_replace($bad_symbols,"",$lines); // remove bad symbols i was using mysql real escape but couldnt get it to work.
print "<center><table border=1 frame=void cellpadding=1 cellspacing=0 align=center rules=all><tr><th>Song Position</th><th>Artist</th><th>Title</th><th>Genre</th></tr>";
while($n < count($linesgood)){ //get number of lines in file or array
$query = mysqli_query($conn1, "SELECT * FROM mp_id3_tags WHERE filename LIKE '$linesgood[$n]'"); //query database for each one
while($row = mysqli_fetch_array($query)){
print "<tr><td>$n</td><td>{$row['artist']}</td><td>{$row['title']}</td><td>{$row['genre']}</td></tr>"; // print whats returned from mysql and print the number it is in the file read from
}
$n = $n + 1;
}
print "</table></center>";
Thanks
require('dbconfig1.php'); // connect to database
$bad_symbols = array("'",","); // set bad symbols
$linesgood = str_replace($bad_symbols,"",$lines); // remove bad symbols i was using mysql real escape but couldnt get it to work.
print "<center><table border=1 frame=void cellpadding=1 cellspacing=0 align=center rules=all><tr><th>Song Position</th><th>Artist</th><th>Title</th><th>Genre</th></tr>";
while($n < count($linesgood)){ //get number of lines in file or array
$query = mysqli_query($conn1, "SELECT * FROM mp_id3_tags WHERE filename LIKE '$linesgood[$n]'"); //query database for each one
while($row = mysqli_fetch_array($query)){
print "<tr><td>$n</td><td>{$row['artist']}</td><td>{$row['title']}</td><td>{$row['genre']}</td></tr>"; // print whats returned from mysql and print the number it is in the file read from
}
$n = $n + 1;
}
print "</table></center>";