Jump to content

php4ever

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by php4ever

  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
  15. Both good examples, thank you. ~ Jared
  16. Thank you sincerely for your reply. I've removed the echo actually but the function call? What again on the syntax to display the results? ~ Jared
  17. I'm trying to create a simple template version notification snippet and I'm missing something but what I'm not sure; <?php function version_check() { $template_version = '2.5'; if (ini_get("allow_url_fopen") == 1) { $lastest_version = @file_get_contents("http://www.jaredritchey.com/downloads/601.txt"); $check = version_compare($template_version, $lastest_version, ">="); } } echo($latest_version); ?> The idea is to look at a directory and compare versions. If there is a newer one then echo a statement or something. If not echo nothing. Is allow_url_fopen a down graded function or did I just approach this wrong? ~ Jared
  18. Anyone have a simple function or snippet that can count files in a remote folder? ~ Jared
  19. I know I found it in these forums but I have looked for hours with no luck. I had a small PHP snippet that I could add to my application that would limit its working to the domain I put in the variable. I'll be if I can't find it in these forums. Could someone point it out if you happen to know where it is? I plan to put it in the header of a template and encrypt the header so it can be used to demo it only on a particular URL or domain. I hope that clarifies which one I was after.
  20. All good information thanks a million. ~ Jared
  21. Oh yeah, I tried like hell to get the line that is commented out to work and couldn't case "/jared/index.html" || $P == "/" || "$P" == "/jared/index.php": The idea is that if a person lands on the homepage without the file extension of either index.php or index.html they would still get the same $data1 results but for the life of me it doesn't work that way unless the actual page is displayed. Is my syntax wrong?
  22. Sorry People I'm not getting my emails when you respond to this thread. Basically this little snippet is only to serve a single simple purpose. IF a person is on a specific web page display an advertisement and or header image specific to that page. The idea was that I would enter the name of the page and then set the contents for that page in a variable or in this case $data and the contents of that would load. I could then do a simple php include for various areas of the site too. Since the only objective here is to first get the http uri and then display the appropriate data accordingly. I made a mistake by posting that code snippet with "current" it was meant to be a generic thing. It could actually be header.php or advertisement.php or randomfooter.php for example. I just needed a simple way of controlling the contents on a per page basis. I'll do what you suggest.
  23. I have a situation where I have different pages and I want to echo different content on those pages by using either an include or simple parse change. The code I have looks tragically heavy. I'd like a lighter cleaner code snippet and I'm open to any suggestions on this. Please don't say "learn to program" that part I already know and I'm working on it. <?php $P=$_SERVER['REQUEST_URI']; switch ($P) { //case "/jared/index.html" || $P == "/" || "$P" == "/jared/index.php": case "/jared/index.php"; $data1 = 'current'; $data2 = ''; $data3 = ''; $data4 = ''; $data5 = ''; break; case "/jared/page2.html": $data1 = ''; $data2 = 'current'; $data3 = ''; $data4 = ''; $data5 = ''; break; case "page3.html"; $data1 = ''; $data2 = ''; $data3 = 'current'; $data4 = ''; $data5 = ''; $data = 'current'; break; case "page4.html": $data1 = ''; $data2 = ''; $data3 = ''; $data4 = 'current'; $data5 = ''; break; case "page5.html": $data1 = ''; $data2 = ''; $data3 = ''; $data4 = ''; $data5 = 'current'; break; default: $data = 'default'; } ?> Then it would be in the HTML as <h1><?php echo($data); ?></h1> (or something to this effect.) All I want the script snippet to do is IF its on a certain page then display the data for that. ~ Jared Ritchey
  24. I've never had a reason to use Javascript in a php file before and I'm having trouble getting it to parse. What could be wrong with this. [code] $display .= '<td width="105" align=right class=box><input name="p1B1" id="p1B1" type="text" value="'.$price.'" onblur="this.value=eedisplayFloatNDTh(eeparseFloatTh(this.value),2); recalc_onclick('p1B1')" tabindex="1" size="14" class=ee101 >';   //..... and the code below  [/code] I'm positive its this and I'm pretty certain its the ('p1B1') but how to handle the single quotes in the brace? [code] recalc_onclick('p1B1')   [/code] The error is, "Parse error: parse error, unexpected T_STRING" Any suggestion would be great. 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.