Jump to content


  • Posts

  • Joined

  • Last visited


Posts posted by guyfromfl

  1. Just a simple schema to get you started:


    Table GiftList

    ID_GiftList (Primary Key, Auto Increment, Not Null...)

    Owner (Integer that holds ID_Users from User table)



    Table GiftListItems

    ID_GiftListItem (Primary Key, Auto Increment, Not Null...)

    GiftList (Stores the integer of the GiftList ID_GiftList... Identifies which GiftList it belongs)



    Table Users








  2. I know this is right in front of me, but I need to add an element to each row of an array..


    I have this array:

    Array ( [0] => Array ( [Elements] => values )
    [1] => Array ( [Elements] => values ) )


    Now, I want to add an element to the end of each one that holds the file name of the originating data.


    The part of code this takes place in, is in a class method to look for duplicates already in the database.  If it is a duplicate, we add the $fileData iteration to the $duplicates array which gets returned to the calling function. It basically looks like this:


    Calling Code:

    while($data = fgetcsv($handle)) {			
    	$leadDataLine = array_combine($headers, $data);
    	// Some data formatting on $leadDataLine not important for this question...
    	// Add the line to the stack
        		$leadData[] = $leadDataLine;
    	//array_push($leadData, $leadDataLine);
    $dup[] = $lead->process($leadData);


    The lead class:

    public function process(&$fileData) {
    	$duplicates = array();
    	// Process the information
    	foreach($fileData as $row) {
    			// If not a duplicate add to the database
    			if (!$this->isDuplicate($row)) {
    				// Add the lead to the database.
    			} else {
    				// is a duplicate, add to $dup
    				$duplicates[] = array("Elements" => $row['Values']);
                                             * Here is where I want to add the file name to the end of $duplicates
                                             * This has to be here because this class handles different sources of data,
                                             * Not all data will have a FileName key
    				if (array_key_exists("FileName", $row))
    					$duplicates["FileName"] =  $row["FileName"];
    					// array_push($duplicates, $row["FileName"]);
    	return $duplicates;



    What happens with the code I have, or using array_push:


    Array ( [0] => Array ( [Elements] => values) [FileName] => correct_file.csv [1] => Array ( [Elements] => Values) ) 


    Notice, it is not on element 1..


    What am I doing wrong here.

  3. You just need to link to a file that will handle the request, and you identify it with GET data.


    I added how to link to that file:


    	$sql=mysql_query("SELECT * FROM `infopessoal` ORDER BY `nome` ASC LIMIT 0 , 30"«»);
    		while($row = mysql_fetch_array($sql))
    			  echo "<tr>";
    			  echo "<td>" . $row['nome'] . "</td>";
    			  echo "<td>" . $row['apelido'] . "</td>";
    			  echo "<td>" . $row['num_funcionario'] . "</td>";
    			  echo "<td><a href='editEmployee.php?id={$row['num_cuncionario']}'><img src='images/insert.gif'><a></td>";
    			  echo "<td><img src='images/lupa.gif'></td>";
    			  echo "<td><input type='image' src='images/perfil.gif'></td>";
    			  echo "</tr>";




    Then in editEmployee.php:

    $sql = "SELECT * FROM `infopessoal` WHERE 'num_cuncionario'={$_GET['id']} LIMIT 1"
    $employee = mysql_fetch_array($sql))
    // Build the table to display data
    echo "<input type='text' value='{$employee['nome']}' />";
    // etc...

  4. I'm suffering from Monday impaired thinking... need a little help..


    Basically, I am taking an array of CSV files, and going through each of them.


    The problem is the code I have written is designed around different header names...For example, the old way has First Name and Last Name fields.  The new on put them together into one field called Full Name.


    In order to use my old code, I just need to take Full Name and explode the values at the first space " ".


    For some reason this doesn't work and I cant figure it out.  It will push First Name on the end of the first element, with no value...


    All the echos are to help try to debug..


    foreach($fileList as $f) {
    if (($handle = fopen(UPLOAD_PATH.$f, "r")) != FALSE) {
    	$headers = fgetcsv($handle);
    	echo $handle;
    	echo count($headers);
    	// Read the rest of the file 
    	while($data = fgetcsv($handle)) {
    		echo strrpos($data['FULL NAME'], " ") . "<br />";			
    		$leadData[] = array_combine($headers, $data);
    		$leadData['First Name'] = substr($leadData['FULL NAME'], 0, strrpos($leadData['FULL NAME'], " "));
    	echo $leadData['First Name'] . "<br />";



    Array ( [0] => Array ( [FULL NAME] => Some Person [PHONE] => 1234567890 [ALT. PHONE] => => you@me.com [ADDRESS] => 123 Birch Drive [CITY] => Anytown [sTATE] => FQ [ZIP] => 98765 [COUNTRY] => US ) [First Name] =>



    Any help would be much appreciated.  Thanks


  5. I agree with AbraCadaver, if you only have say 3 different pages you are going to run (New, Edit, Delete, or whatever..) then you should use a switch somewhere to direct you to the correct page.  Then you can use the default case to bounce you to a generic page if invalid data is entered.


    I still am not sure exactly what you are looking for, but you need to reference the GET data properly.

  6. Are you trying to get the GET data passed in the URL?


    If so, you need to refer to it by the GET super global...


    if($_GET['action'] == "Edit_Agents" && $_GET['do'] == "Edit" && $_GET['id'] == $_SESSION['id']){ } ()


    The data passed after the ? in the URL is automatically saved in the $_GET array when a form is submitted.

  7. What happens if you do not unset an array before the script is done executing?


    I am running through thousands of CSV files, parsing data for hundreds of thousands of customers.  It works fine for the first 5/6 hours then starts bogging down bad. 


    I run about 5-10 CSVs per execution...I'm wondering if unsetting the arrays in the script would help this or not...I thought they would be unallocated after the script ends. Am I wrong?

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.