I finally got CLOSE to what I want with the help of Sephedo and Varun. Here is the code....
What IS happening now is that I'm gettting mysql error wrong syntax because of 's in the txt file data. How and where would I make the sql query ignore the 's and any other char that might throw off mysql
<?php
//Open connection
$servername = "localhost";
$username = "testing";
$password = "*******";
$dbname = "zadmin_testing";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
/**
* @author - Sephedo
* @for - Randall @ Stackoverflow
* @question - http://stackoverflow.com/questions/18704981/read-each-line- of-text-of-each-file-in-a-directory-and-place-into-array/18705231#18705231
*/
$directory = 'data/'; // The directory to the lesson text files
$linesToReturn = 9; // Set to nine for the number of lines in each text file ( for expansion? )
// Find all files in the directory which are .txt files
foreach( glob( $directory . "*.txt" ) as $filename )
{
// Open the file
if( $handle = @fopen( $filename, "r") )
{
$x = 0; // Start the line counter
// Cycle each line until end or reach the lines to return limit
while(! feof( $handle ) or $x < $linesToReturn )
{
$line = fgets($handle); // Read the line
$lessons[$filename][] = $line;
$x++; // Increase the counter
}
// This lines makes sure that are exactly x# of lines in each lesson
if( count( $lessons[$filename] ) != $linesToReturn ) unset( $lessons[$filename] );
}
}
// creates a blank list if no files or valid files were found.
if(! isset( $lessons ) ) $lessons = array();
foreach( $lessons AS $file => $details )
//Creates your data into a query
{
$sql = "INSERT INTO videos (date, title, type, cover, genre, vrating, path, mrating, description) VALUES ('$details[0]', '$details[1]', '$details[2]', '$details[3]', '$details[4]', '$details[5]', '$details[6]', '$details[7]', '$details[8]')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully <br>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
//Close mysql connection
mysqli_close($conn);
?>
THE CODE I STARTED FROM
/**
* @author - Sephedo
* @for - Randall @ Stackoverflow
* @question - http://stackoverflow.com/questions/18704981/read-each-line- of-text-of-each-file-in-a-directory-and-place-into-array/18705231#18705231
*/
$directory = 'lessons/'; // The directory to the lesson text files
$linesToReturn = 4; // Set to four for the number of lines in each text file ( for expansion? )
// Find all files in the directory which are .txt files
foreach( glob( $directory . "*.txt" ) as $filename )
{
// Open the file
if( $handle = @fopen( $filename, "r") )
{
$x = 0; // Start the line counter
// Cycle each line until end or reach the lines to return limit
while(! feof( $handle ) or $x < $linesToReturn )
{
$line = fgets($handle); // Read the line
$lessons[$filename][] = $line;
$x++; // Increase the counter
}
// This lines makes sure that are exactly 4 lines in each lesson
if( count( $lessons[$filename] ) != $linesToReturn ) unset( $lessons[$filename] );
}
}
// creates a blank list if no files or valid files were found.
if(! isset( $lessons ) ) $lessons = array();
// The rest of the page just builds a simple table to display each lesson.-
echo '<h1>Lesson Plans</h1>';
echo '<table>';
echo '<th>Lesson Number</th><th>Lesson Title</th><th>Description</th><th>Due Date</th>';
foreach( $lessons as $file => $details )
{
echo '<tr><td>' . $details[0] . '</td><td>' . $details[1] . '</td><td>' . $details[2] . '</td><td>' . $details[3] . '</td></tr>';
}
echo '</table>';
?>