Array or SQL query in loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anon404
Forum Newbie
Posts: 12
Joined: Wed Dec 23, 2009 4:09 am

Array or SQL query in loop

Post by anon404 »

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);
}
?>
Post Reply