Jump to content

php4ever

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

php4ever's Achievements

Member

Member (2/5)

0

Reputation

  1. I posted it here; http://livedemosite.com/fixcsv/testing_full.php If you run the script, it just duplicates the output in a loop of some sort. The idea behind the above script is to take that nasty CSV file and fix the text data by removing all those extra breaks and html code. I know it now works properly for formatting because looking at the 2 left columns I see the main ID and the secondary ID consistently. What doesn't work, is it keeps looping. You can for instance open your FireFox, hit CTRL+F and search for 3966497 and you will see that the output has been produced again and again. There are 200 rows in the CSV, none are the same.
  2. Ok here you go // the column-array.php is just the array matching that in the data.csv. require_once("column-array.php"); $fp = fopen("data.csv", "r"); // getZip not used this version function getZip($full) { $pieces = explode(' ', $full); $zip = explode('(', $pieces[count($pieces)-1]); $zip = explode(')', $zip[1]); return $zip[0]; } $pre=""; while (($data = fgets($fp,4096)) !== FALSE) { $data=str_replace("\r\n","",$data); if(trim($data)=="" or substr($data,strlen($data)-1,1)!='"' or substr($data,strlen($data)-2,2)==',"') { $pre.=$data; } else { $data=$pre.$data; $data=str_replace(array(',""','","','"',"'","html","\r\n"),array("","|","","","PHP"," "),$data); $data=preg_replace("/\r|\n|\v|\r\n/smUi"," ",$data); $data_elements=explode("|",$data); } //////////////////////////////////////////////////////////////////////////// // USED TO ECHO FIELD COLUMNS IN A TABLE - Used For Testing Output //////////////////////////////////////////////////////////////////////////// echo("<table border=2 cellpadding=5 cellspacing=5>"); $i++; echo("<tr>"); foreach($data_elements as $k) { echo("<td valign=top width='20' style='overflow:hidden;'>"); echo($k); echo("</td>"); } echo("</tr>"); echo("</table>"); continue; $listings++; //} } fclose($fp);
  3. I have a script that opens up a CSV file and outputs to a table for testing. It ultimately inserts into a MySQL but the code below literally duplicates every third row consistently. I'm 95% sure its in the "WHILE" area. Is there enough code here for someone to point out an error. If not I can put the code up live and if you want a fee for fixing just PM me please. $fp = fopen("residential-data.csv", "r"); $listings=-1; function getZip($full) { $pieces = explode(' ', $full); $zip = explode('(', $pieces[count($pieces)-1]); $zip = explode(')', $zip[1]); return $zip[0]; } $pre=""; while (($data = fgets($fp,4096)) !== FALSE) { $data=str_replace("\r\n","",$data); if(trim($data)=="" or substr($data,strlen($data)-1,1)!='"' or substr($data,strlen($data)-2,2)==',"') { $pre.=$data; }
  4. Thats nice, it doesn't appear to allow me to redistribute the app I'm creating. If I have all the tables in an HTML, is it over complex to have someone just code this or is it rather involved?
  5. I have three small tables and I'm looking for a clean, light, framework CRUD generator that I can use. Are there any that are small and light that dont require a full blown install like Symphony or phpObject Generator etc... Jared
  6. Thanks you, I need to add links to the videos describing the project. I hope that is okay to do as well.
  7. Is it okay to post projects for hire in here? I have about a dozen small tasks I need done. Jared
  8. With ACCESS or Jet databases that have a nice way to create joins and relationships making everything super lean is exceptionally easy to understand for the most part. With MySQL this would require a ton of PHP coding to keep them together when it comes to searches and such so I want to create all data in larger tables to accommodate more fields as opposed to breaking up each field element into multiple rows. Is this a better way to build such a DB. ID | Date | Expiration | TTD | LBC | (then) 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 etc and so on. In table 2 I would have 1 Name 2 City 3 State 4 Country 5 Donation 6 TaxID Does that seem like a logical way to make the DB extensible enough to change yet keep performance super tight?
  9. Yeah that unfortunately is not an option on this server. That was my first thought. Is there no way to redirect from one script to the next via SHELL. If not I can try and bury it somewhere its not visitor accessible.
  10. The problem is the script time. If I require it, the server times out. The file being processed is rather large and is in many pieces. Breaking it up seems to work on the server for the time out issue.
  11. I'm using ob_start(); in a script as follows for redirect and I'm seeking an alternative that can work from the shell <?php ob_start(); // MY Script here sleep(10); header ("Location: http://www.jaredritchey.com/project/testing/steptwo.php"); ob_flush(); ?> This works fine however when I move it to the root of my server there is no way to use the browser direct obviously but there must be an alternative. I could setup two CRONs but the problem is that the first script processes a CSV file and the size changes frequently so the time would also change. Any assistance is appreciated. THX, Jared.
  12. Yeah this just drives me nuts, I'll have to hire this one out. Its still pulling the first row.
  13. I have a text file that has about 2,000 rows of data. Unfortunately it also has column headers and my script will not skip the first row regardless of all my attempts. BUSOEMPS BUSOLSTR BUSOPRKG 7 No Yes 3 Yes No 6 Yes No 0 Yes Yes 0 No Yes 7 Yes Yes 0 No No 0 NO No 0 NO Yes 0 Yes Yes 0 No Yes 0 No Yes 6 Yes Yes 0 No Yes require_once('dbsettings.php'); $sqltablepref = "set3_"; $insert_fields=array( "BUSOEMPS"=>"0", "BUSOLSTR"=>"1", "BUSOPRKG"=>"2" ); function explode_features($insert_fields_features, $features) { $elements = explode(",", $features); $newStr = ""; $i=0; foreach ($elements as $field_element) { //echo($bit); if (array_key_exists($field_element,$insert_fields_features)) { if ($insert_fields_features[$field_element]) $newStr .= $insert_fields_features[$field_element].", "; } } return substr($newStr,0,-2); } $specified_user_id=""; $sql="select userdb_id from ".$sqltablepref."userdb where userdb_user_name like 'Manager'"; $select=mysql_query($sql); $rows=mysql_num_rows($select); if($rows==1) { $row=mysql_fetch_array($select); $specified_user_id=$row[0]; } else $specified_user_id=2; $specified_id=""; $select=mysql_query($sql); $rows=mysql_num_rows($select); if($rows==1) { $row=mysql_fetch_array($select); $specified_id=$row[0]; } else $specified_id=2; $fp = fopen("business_list.csv", "r"); while (($data = fgets($fp,4096)) !== FALSE) { $data=str_replace('","',"|",$data); $data=str_replace('"',"",$data); $data=str_replace("'","",$data); $data_elements=explode("|",$data); // the data elements below are for user first name and last name which is field 45 and 49 $sql="select userdb_id from ".$sqltablepref."userdb where userdb_user_name like '".$data_elements[45].$data_elements[49]."'"; $select=mysql_query($sql); $rows=mysql_num_rows($select); $row=mysql_fetch_array($select); if($rows==1) { continue; } $user_id=0; $sql="select max(userdb_id) from ".$sqltablepref."userdb"; $select=mysql_query($sql); while($row=mysql_fetch_array($select)) $user_id=$row[0]+1; if(strlen($data_elements[45]) && strlen($data_elements[49])) { $sql= "INSERT INTO " . $myconfig['table_prefix'] . "userdb VALUES (".$user_id.", '".$data_elements[45].$data_elements[49]."', '".$data_elements[53]."', '".$data_elements[45]."', '".$data_elements[49]."', 'Contact Jared Ritchey For Details', 'no', 'no', 'no', 'no', 'no', 'no', '2008-07-16', 'no', 'no', '2008-07-16 11:20:49', 1, 'no', 'no', 'no', 'yes', 'no', -1, 'no', 'no', 'no', 'no', 'no', 'no', 'no' )"; mysql_query($sql); $specified_user_id=0; $sql="select userdb_id from ".$sqltablepref."userdb where userdb_user_name like '".$data_elements[45].$data_elements[49]."'"; $select=mysql_query($sql); while($row=mysql_fetch_array($select)) $specified_user_id=$row[0]; foreach($agent_fields as $field=>$num) { $sql = "INSERT INTO ".$sqltablepref."userdbelements SET userdbelements_field_name = '".$field."', userdbelements_field_value = '".$data_elements[$num]."', userdb_id =".$specified_user_id; mysql_query($sql); } } } fclose($fp); echo("business directory added"."<br />"); What happens is that when I run this script to update my directory it includes the very top row of the text file which is the column headers as a record. I dont want the top row included as a record.
  14. Thats good stuff. I love the tutorials, thanks for posting. ~ Jared
×
×
  • 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.