mogx21 Posted September 13, 2008 Share Posted September 13, 2008 Alright, well I'll start off describing the issue. Basically, I'm using code to take MySQL data from database1 and create a .cvs file. Then I'm importing that .cvs file and creating Taskfreak objects with the data, which is also adding it to database2. So far, I can create the .cvs file, but when it tries to make the TaskFreak object I am receiving, "Fatal error: Cannot use string offset as an array in /home/content/m/o/g/mogx21/html/taskfreak/excel.php on line 118." Following code is seperate by file. <?php include 'createInfo.php'; function getDatabaseData() { $host="*******"; // Host name $username="*******"; // Mysql username $password="*******"; // Mysql password $db_name="*******"; // Database name $tbl_name="*******"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT id FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $id = mysql_fetch_row($result); $count = 1; //mysql_num_rows($result); //Get Age $sql = "SELECT age FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Age = mysql_fetch_row($result); //Get Style $sql = "SELECT style FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Style = mysql_fetch_row($result); //Get Reason $sql = "SELECT reason FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Reason = mysql_fetch_row($result); //Get Experience $sql = "SELECT experience FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Exp = mysql_fetch_row($result); //Get talents $sql = "SELECT wsxTalents FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Talents = mysql_fetch_row($result); //Get Reference $sql = "SELECT referral FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Ref = mysql_fetch_row($result); //Get Name $sql = "SELECT name FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Name = mysql_fetch_row($result); //get DFForum $sql = "SELECT dfForum FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $dfForum = mysql_fetch_row($result); //get wsxForum $sql = "SELECT wsxForum FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $wsxForum = mysql_fetch_row($result); //getRace $sql = "SELECT dfRace FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $race = mysql_fetch_row($result); //getClass $sql = "SELECT dfClass FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $class = mysql_fetch_row($result); //GetAIM $sql = "SELECT aimSn FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $aim = mysql_fetch_row($result); if($count > 0) { $Age = $Age[0]; $Style = $Style[0]; $Reason = $Reason[0]; $Exp = $Exp[0]; $Talents = $Talents[0]; $Ref = $Ref[0]; $Name = $Name[0]; $dfForum = $dfForum[0]; $wsxForum = $wsxForum[0]; $race = $race[0]; $class = $class[0]; $aim = $aim[0]; $id = $id[0]; $Description = '' .'Age: ' .$Age .'<br><br> Style: ' .$Style .'<br><br> Reason: ' .$Reason .'<br><br> Experience: ' .$Exp .'<br><br> Talents: ' .$Talents .'<br><br> Reference: ' .$Ref .'<br><br> Character Name: ' .$Name .'<br><br> Darkfall Forum Username: ' .$dfForum .'<br><br> Wessex Forum Username: ' .$wsxForum .'<br><br> Character Race: ' .$race .'<br><br> Character Class: ' .$class .'<br><br> AIM: ' .$aim; createCSV('5', 'Work', '', 'Wessex Application', 'Duchy of Wessex applicants', 'Application - '.$Name, $Description, 'Clerk', 'Public', '0',$id); $count++; } } getDatabaseData(); ?> Next.. <?php include 'excel.php'; $host="*******"; // Host name $username="*******"; // Mysql username $password="*******"; // Mysql password $db_name="*******"; // Database name $tbl_name="*******"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); function createCSV($Priority, $Context, $Deadline, $Project, $ProjDesc, $Title, $Desc, $User, $Type, $Status,$id) { $sql = "SELECT id FROM applicants WHERE beenCreated='0'"; $result = mysql_query($sql); $numberToCreate = 1; //mysql_num_rows($result); $created = 0; while($created < $numberToCreate) { $csv = '' .$Priority .',' .$Context .',' .$Deadline .',' .$Project .',' .$ProjDesc .',' .$Title .',' .$Desc .',' .$User .',' .$Type .',' .$Status; $columns = "'Priority' , 'Context', 'Deadline','Project','Project Desc','Title','Description','User','Type','Status'"; $f=fopen('dataBase.csv', 'w'); fwrite($f, $csv); fclose($f); mysql_query("UPDATE applicants SET beenCreated='1' WHERE id='$id'"); //unlink("dataBase.csv"); $created++; } } ?> Next.. <?PHP /****************************************************************************\ * Excel Spreadsheet Plugin 4 TaskFreak! * * Version: 0.0.4 * * Author: Searcher <[email protected]> * ****************************************************************************** * For: TaskFreak! Multi User * * Version: 0.6.1 * * Authors: Stan Ozier <[email protected]> * * License: http://www.gnu.org/licenses/gpl.txt (GPL) * \****************************************************************************/ ob_start(); // [=== HTML ===================================================================] [original] $pPageIsPublic = false; include '_common.php'; // ~~~ EXCEL PLUGIN SETTINGS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [config] define(PLG_EXCEL_VER, "0.0.4"); define(PLG_EXCEL_TITLE, "ExcelCSV_".PLG_EXCEL_VER); define(PLG_EXCEL_DIR, PRJ_ROOT_PATH."plugins/data/installed/".PLG_EXCEL_TITLE."/"); $_SERVER['QUERY_STRING'] = 'import'; $_GET['import'] = 'yup'; $_SESSION['CSV_Import'] = 'dataBase.csv'; include PRJ_INCLUDE_PATH.'html/header.php'; // [=== CSV Upload =============================================================] [ok] if ($_FILES['CSV_Upload']) { // form upload $_SESSION['CSV_Import'] = 'dataBase.csv'; $CSV_FileName = basename($_FILES['CSV_Upload']['name']); $CSV_File = $_FILES['CSV_Upload']['tmp_name']; //30 } ?> <style> table { font-family:tahoma; font-size:11px } </style> <br /> <table align="center"> <tr> <td colspan="4" align="center"><strong>Excel/CSV Import & Export</strong></td> </tr> </table> <br /> <br /> <table align="center"> <tr> <td align="center" style="color:#990000"><strong>Sample CSV File</strong></td> </tr> </table> <br /><br /> <br /> <table align="center"> <tr> <td align="center" style="color:#990000"><strong>Imported CSV File Confirmation</strong></td> </tr> </table> <table align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr style="background-color:#999999"> <td align="center"><strong>Priority</strong></td> <td align="center"><strong>Context</strong></td> <td align="center"><strong>Deadline</strong></td> <td align="center"><strong>Project</strong></td> <td align="center"><strong>Project Desc</strong></td> <td align="center"><strong>Title</strong></td> <td align="center"><strong>Description</strong></td> <td align="center"><strong>User</strong></td> <td align="center"><strong>Type</strong></td> <td align="center"><strong>Status</strong></td> </tr> <?php $CSV_Data = file($CSV_File); $CSV_Line_Counter = 0; for ($i=0; $i < count($CSV_Data); $i++) { $CSV_Line = explode(",", $CSV_Data[$i]); if (is_numeric($CSV_Line[0])) { $CSV_Temp_Counter = 0; foreach($CSV_Line as $CVS_Temp) { $_SESSION['CSV_Import'][$CSV_Line_Counter][$CSV_Temp_Counter] = $CVS_Temp; $CSV_Temp_Counter++; } $CSV_Line_Counter++; ?> <tr style="background-color:#fff"> <td align="center"><?php echo $CSV_Line[0]; ?></td> <td align="center"><?php echo $CSV_Line[1]; ?></td> <td align="center"><?php echo $CSV_Line[2]; ?></td> <td><?php echo $CSV_Line[3]; ?></td> <td><?php echo $CSV_Line[4]; ?></td> <td><?php echo $CSV_Line[5]; ?></td> <td><?php echo $CSV_Line[6]; ?></td> <td align="center"><?php echo $CSV_Line[7]; ?></td> <td align="center"><?php echo $CSV_Line[8]; ?></td> <td align="center"><?php echo $CSV_Line[9]; ?></td> </tr> <?php } } ?> </table> <br /> <table align="center"> <tr> <td style="color:#006600"><strong>Confirm data</strong></td> <td><a href="?import&confirm=yup" title="Confirm"><img border="0" src="plugins/data/default/images/ok.gif" alt="Confirm"></a></td> </tr> </table> <?php if ($_GET['confirm']) { ?> <br /> <table align="center"> <tr> <td style="color:#006600"> <?php for ($i=0; $i < count($_SESSION['CSV_Import']); $i++) { // get project id $ProjectName = addslashes($_SESSION['CSV_Import'][$i][3]); $ProjectDesc = addslashes($_SESSION['CSV_Import'][$i][4]); $Qry = "SELECT projectId FROM ".TZN_DB_PREFIX."_project where name = '$ProjectName'"; $Res = @mysql_result(mysql_query($Qry),0,projectId); $projectId = $Res; if (!$Res) { // insert new project $Qry = "INSERT INTO ".TZN_DB_PREFIX."_project (name,description) VALUES('$ProjectName','$ProjectDesc')"; mysql_query($Qry) or die(mysql_error()."<br>".$Qry."<hr>"); $projectId = mysql_insert_id(); // insert project status $Qry = "INSERT INTO ".TZN_DB_PREFIX."_projectStatus (projectId,statusDate,memberId) VALUES($projectId,'".date("Y-m-d H:i")."',1)"; mysql_query($Qry) or die(mysql_error()."<br>".$Qry."<hr>"); } // get context $Context = array_search($_SESSION['CSV_Import'][$i][1], $GLOBALS['langItemContext']); // get member $UserName = $_SESSION['CSV_Import'][$i][7]; $Qry = "SELECT memberId FROM ".TZN_DB_PREFIX."_member where username = '$UserName'"; $Res = @mysql_result(mysql_query($Qry),0,memberId); $memberId = $Res; // get type switch($_SESSION['CSV_Import'][$i][8]) { case 'public': $Type = 0; break; case 'internal': $Type = 1; break; case 'private': $Type = 2; break; } // insert task $Priority = $_SESSION['CSV_Import'][$i][0]; $Deadline = $_SESSION['CSV_Import'][$i][2]; $TaskName = addslashes($_SESSION['CSV_Import'][$i][5]); $TaskDesc = addslashes($_SESSION['CSV_Import'][$i][6]); $AuthorId = 1; $Qry = "INSERT INTO ".TZN_DB_PREFIX."_item (priority,context,deadlineDate,projectId,title,description,memberId,showPrivate,authorId) VALUES($Priority,$Context,'$Deadline',$projectId,'$TaskName','$TaskDesc',$memberId,$Type,$AuthorId)"; mysql_query($Qry) or die(mysql_error()."<br>".$Qry."<hr>"); $itemId = mysql_insert_id(); // get status key switch($_SESSION['CSV_Import'][$i][9]) { case 0: $Status = 0; break; case 20: $Status = 1; break; case 40: $Status = 2; break; case 60: $Status = 3; break; case 80: $Status = 4; break; case 100: $Status = 5; break; } // insert task status $Qry = "INSERT INTO ".TZN_DB_PREFIX."_itemStatus (itemId,statusDate,statusKey,memberId) VALUES($itemId,'".date("Y-m-d H:i")."',$Status,1)"; mysql_query($Qry) or die(mysql_error()."<br>".$Qry."<hr>"); } ?> <strong>CSV Imported!</strong> </td> </tr> </table> <?php # TaskFreak Data ~~~~~~~~~~~~~~~~~ if (method_exists('ItemTimeClock','formatTime')) { // check if TimeClock is installed $objClockFormat = new ItemTimeClock(); // format time } for ($i=0; $i<count($_SESSION['plg_Cal_Live']); $i++) { $objItem = new ItemStats(); $objItem->setUid($_SESSION['plg_Cal_Live'][$i]); $objItem->load(1); // additional info $Qry = "SELECT description FROM ".TZN_DB_PREFIX."_project where projectId = '".$objItem->project->id."'"; $projDesc = @mysql_result(mysql_query($Qry),0,'description'); $Qry = "SELECT username FROM ".TZN_DB_PREFIX."_member where memberId = '".$objItem->member->id."'"; $taskOwner = @mysql_result(mysql_query($Qry),0,'username'); switch($objItem->showPrivate) { case '0': $taskType = 'public'; break; case '1': $taskType = 'internal'; break; case '2': $taskType = 'private'; break; } $Qry = "SELECT SUM(".TZN_DB_PREFIX."_itemTimeClock.subtotalTime) as itemTotalTime FROM ".TZN_DB_PREFIX."_itemTimeClock WHERE itemId = ".$objItem->id; $itemTime = @mysql_result(mysql_query($Qry),0,'itemTotalTime'); if (method_exists('ItemTimeClock','formatTime')) { $itemTime = $objClockFormat->formatTime($itemTime,1); } ?> <tr style="background-color:#fff"> <td align="center"><input name="chk_<?php echo $objItem->id; ?>" id="chk_<?php echo $objItem->id; ?>" type="checkbox" checked="checked" onclick="this.blur()" /></td> <td align="center"><?php $objItem->p('priority'); ?></td> <td align="center"><?php echo $objItem->getContext(1); ?></td> <td align="center"><?php echo $objItem->deadlineDate; ?></td> <td align="center"><?php $objItem->project->p('name','-'); ?></td> <td align="center"><?php echo $projDesc; ?></td> <td align="center"><?php $objItem->p('title'); ?></td> <td align="center"><?php $objItem->p('description'); ?></td> <td align="center"><?php echo $taskOwner; ?></td> <td align="center"><?php echo $taskType; ?></td> <td align="center"><?php $objItem->pStatus(); ?></td> <?php if (method_exists('ItemTimeClock','formatTime')) { ?> <td align="center"><?php echo $itemTime; ?></td> <?php } ?> </tr> <?php } ?> </table> <br /> <table align="center"> </table> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/ Share on other sites More sharing options...
mogx21 Posted September 14, 2008 Author Share Posted September 14, 2008 Modest bump Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-640800 Share on other sites More sharing options...
jordanwb Posted September 14, 2008 Share Posted September 14, 2008 I don't know about the error, but in the first file you could reduce the code by 60% by merging the several queries together: $sql = "SELECT id FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $id = mysql_fetch_row($result); $count = 1; //mysql_num_rows($result); //Get Age $sql = "SELECT age FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Age = mysql_fetch_row($result); //Get Style $sql = "SELECT style FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Style = mysql_fetch_row($result); //Get Reason $sql = "SELECT reason FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Reason = mysql_fetch_row($result); //Get Experience $sql = "SELECT experience FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Exp = mysql_fetch_row($result); //Get talents $sql = "SELECT wsxTalents FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Talents = mysql_fetch_row($result); //Get Reference $sql = "SELECT referral FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Ref = mysql_fetch_row($result); //Get Name $sql = "SELECT name FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $Name = mysql_fetch_row($result); //get DFForum $sql = "SELECT dfForum FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $dfForum = mysql_fetch_row($result); //get wsxForum $sql = "SELECT wsxForum FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $wsxForum = mysql_fetch_row($result); //getRace $sql = "SELECT dfRace FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $race = mysql_fetch_row($result); //getClass $sql = "SELECT dfClass FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $class = mysql_fetch_row($result); //GetAIM $sql = "SELECT aimSn FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $aim = mysql_fetch_row($result); To this: $sql = "SELECT * FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); Line 118 is this: $ProjectName = addslashes($_SESSION['CSV_Import'][$i][3]); I see nothing wrong. Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-641163 Share on other sites More sharing options...
mogx21 Posted September 14, 2008 Author Share Posted September 14, 2008 If I were to merge them, how would I retrieve the individual field values into variables? Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-641524 Share on other sites More sharing options...
jordanwb Posted September 14, 2008 Share Posted September 14, 2008 $sql = "SELECT * FROM application WHERE beenCreated='0'"; $result = mysql_query($sql); $application = mysql_fetch_row($result); $id = $application['id']; $age = $application['age']; // et cetera, et cetera The * means all fields in that row. Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-641588 Share on other sites More sharing options...
mogx21 Posted September 15, 2008 Author Share Posted September 15, 2008 Alright, thanks. I'm still getting the issue with Excel.php I'm assuming its a problem with either CSV_Import or if ($_FILES['CSV_Upload']) { // form upload $_SESSION['CSV_Import'] = 'dataBase.csv'; $CSV_FileName = basename($_FILES['CSV_Upload']['name']); $CSV_File = $_FILES['CSV_Upload']['tmp_name']; //30 Maybe the data held by dataBase.csv? I'm very new to php Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-641596 Share on other sites More sharing options...
jordanwb Posted September 15, 2008 Share Posted September 15, 2008 Alright, thanks. No prob. I'm still getting the issue with Excel.php I'm assuming its a problem with either CSV_Import or if ($_FILES['CSV_Upload']) { // form upload $_SESSION['CSV_Import'] = 'dataBase.csv'; $CSV_FileName = basename($_FILES['CSV_Upload']['name']); $CSV_File = $_FILES['CSV_Upload']['tmp_name']; //30 Maybe the data held by dataBase.csv? I'm very new to php The only thing I can think of is that you forgot to call session_start() at the beginning of your script. Link to comment https://forums.phpfreaks.com/topic/124110-complicatedimo-problem/#findComment-641668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.