Arrays - Why can't I print value in table?
Posted: Sun Apr 19, 2009 3:42 pm
I am trying to populate a table in mySQL by exploding a file from a website. I have got it to add the fields correctly, but not the foreign key of the other table it is supposed to reference. I have tried to create a function to select the primary key(pkDeptID) from the table as seen here in validation_functions.php:
And then this is the code in order to populate all the information into the table(tblClasses):
When I echo out $j in order to check to see if it is obtaining the correct number to insert into tblClasses, it prints "ArrayArrayArrayArray...etc." instead of the correct primary key. Can someone please tell me what I am doing wrong, and how I can correct this to obtain the number(pkDeptID) of the table in order to make it the foreign key in tblClasses?
Code: Select all
function deptIDNum($dept){
include("connect.inc");
//Create your SQL statement
$sql = "SELECT pkDeptID ";
$sql .= "FROM tblDept ";
$sql .= "WHERE fldDeptName ='" . $dept . "'";
$results = $myDatabase->select($sql);
return $results;
}Code: Select all
<?php
$lines = file('http://giraffe.uvm.edu/~rgweb/batch/curr_enroll_fall.txt');
$i=1;
//files to connect to database
include("db.inc");
include("error.inc");
include("mydb.inc");
include ("validation_functions.php");
while ($i <= 3030)
{
list($dept, $num, $title) =
explode(",", $lines[$i]);
// create sql statements to insert into table
$sql = "INSERT INTO ";
$sql .= "tblClasses ";
$sql .= "SET ";
$sql .= "fkDeptID='" . $j . "',";
$sql .= "fldClassNum='" . $num . "',";
$sql .= "fldClassName='" . $title . "';";
$j=deptIDNum($dept);
echo $j;
//Make a connection
include("connect.inc");
// execute SQL statement
//$className=$myDatabase->insert($sql);
$i++;
}
?>