Array or SQL query in loop
Posted: Wed Dec 23, 2009 4:20 am
Before going any further i need to know whether i should add strings to an array before adding them to a database or add if i should add strings by queries in a loop.
Code: Select all
<?php
function updateFiles()
{
mysql_connect("localhost", "root", "pw") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
mysql_query("INSERT INTO files (filename, type) VALUES('test1', 'avi')") or die(mysql_error());
}
function viewFiles()
{
mysql_connect("localhost", "root", "pw") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$path = "/var/www/files";
$dh = opendir($path);
while ($file = readdir($dh))
{
if($file!="." && $file!="..")
echo "<a href='files/$file'>$file</a><br/>";
}
closedir($dh);
}
?>