Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. If the data is not freely available via an API or feed then its guaranteed that the website owner doesn't want you to have the data (or hasn't the skills to create a data source). However most article sites contain user submitted articles, they do not belong to the website owner so you will find the same article all over the web. If you want these articles then you need to write a bot that can extract the page content and then filter all the shit out (html, etc) and leave the article. There will not be a specific script to do this as every website is different, however the tools to make it work are available. Look at CURL. Be careful when scraping data.
  2. $x = "13,2"; $vals = explode(",",$x); $articleId = $vals[0]; $pictureId = $vals[1];
  3. As the requirement is to have past gigs in a separate table / section adding html in this control structure would not work as you are looping through the entire result set. If using 1 query you would build a multidimensional associated array i.e $gigs['future'], $gigs['past']. Then loop each array into its own section. Using 2 queries is not expensive and a simpler implementation.
  4. I would disagree! For simplicity a second query is not expensive. Fill your tables into the appropriate places: <?php // future gigs $result = mysql_query("SELECT * FROM Schedule WHERE FROM_UNIXTIME(day) >= CURDATE() ORDER BY day ASC"); while($row = mysql_fetch_assoc($result)) { } // past gigs $result = mysql_query("SELECT * FROM Schedule WHERE FROM_UNIXTIME(day) < CURDATE() ORDER BY day ASC"); while($row = mysql_fetch_assoc($result)) { } ?>
  5. This is 100% correct. You must have ammended it somewhere. <?php $recipient = explode("\n", $_POST['recipient']); if(is_array($recipient)) { $results = array(); foreach($recipient as $number) { $number = trim($number); if(ereg('[0-9]+', $number, $regs)) { // number is valid $results['valid'][] = $number; } else { // entry is invalid $results['invalid'][] = $number; } } // check for invalid entries if(count($results['invalid'])) { print "Invalid Entries: ".count($results['invalid'])."<br />"; //print "The following entries are invalid:<br />".implode("<br />",$results['invalid'])."<br />"; } // display valid entries if(count($results['valid'])) { print "Valid Entries: ".count($results['valid']); //print "The following entries are valid:<br />".implode("<br />",$results['valid'])."<br />"; } } else { print "Missing input"; exit(); } ?>
  6. yes, is the day field a unix timestamp?
  7. No it wont. Are you sure the correct keys are used? $results['valid'] $results['invalid']
  8. Also displaying data using the DOM from AJAX requests makes it difficult to scrape.
  9. Had a play with this recently. Sweet for mining data from AJAX driven sites using DOM. http://www.iopus.com Can use PHP via a COM object
  10. Bad syntax echo "<option value='".$row['ii'].",".$row['bi']."'>".$row['io']."</option>\n";
  11. <?php print "Valid Entries ".count($results['valid'])."<br />"; print "Invalid Entries: ".count($results['invalid']); ?>
  12. Try this out. Be careful. Your csv data has an error. The last delimiter should be : not ; Email:LastName:FirstName:Assignment1,100:Assignment2,100:Quiz1,50 someone@email.com:Doe:John:95:86:40 someone_else@email.com:Doe:Jane:80:96:45 <table style='font-family:arial; text-align:left; font-size:12px;' width="100%"> <?php $handle = fopen("test.csv", "r"); $row = 1; $totals = array(); while(($data = fgetcsv($handle, 1000, ":")) !== FALSE) { $colnum = 0; print "<tr>\n"; foreach($data as $col) { // header row if($row == 1) { $total = explode(",",$col); $totals[] = $total[1]; $col = $total[0]; } else { $percentage = is_numeric($totals[$colnum]) ? " (".(($col / $totals[$colnum]) * 100)."%)" : false; } print "<t".(($row == 1) ? "h" : "d").">".$col.((is_numeric($totals[$colnum]) && $row > 1) ? " / ".$totals[$colnum] : false).$percentage."</t".(($row == 1) ? "h" : "d").">\n"; $colnum++; } print "</tr>\n"; $row++; } fclose($handle); ?> </table>
  13. So for John Doe you would divide 100 by 95 to give you 1.05263 for assignment 1 and display it how?
  14. Use the same for your getter. Make sure you handle your exceptions gracefully.
  15. At the end of the day, if someone badly wants your data, they will get it. However you can make it more difficult to obtain. As I have not seen what sort of data you are displaying it is not easy to say how simple it is to extract. Couple of ideas: 1. Use a CAPTCHA graphic within a form before any data can be accessed. If the code is correctly inserted set a session. Check for this session on all pages displaying data. 2. As suggested check the number of requests per IP. This is not foolproof however as someone with a large number of proxies could change their IP on every request.
  16. Search the forum for paginating results. Your pagination could consist of 2 links, 'prev 12', 'next 12'
  17. This is your requirement yes? To find cities, towns, train stations, mcdonalds, whatever, within a given distance of a set point you use geo co-ordinates (latitude and longitude). It seems that you have this data in your database. So, once you have the lat, lon of your start point you can use what is called the haversine formula to find the nearest... You are using this in the code, yes, but you do not have to. Use in the actual query to obtain the results required. The query that you are currently using is highly inefficient.
  18. Please note: requires php >= 5.1 <?php $x = new Objekt(); if(property_exists($x, 'baz')) { $x->baz = 9; } else { print "property does not exist"; } ?>
  19. These queries are poor for distance calculations. As mentioned use a haversine formula. Add indexes to zipcode, latitude, longitude. <?php // get all zipcodes within 12 mile radius $latitude = 36.28698; $longitude = 95.69952; $distance = 12; $query = " SELECT a.description, a.zipcode, z.city, z.state, SQRT(POW(69.1 * (z.latitude - ".$latitude."), 2) + POW(69.1 * (".$longitude." - z.longitude) * COS(latitude / 57.3) , 2)) AS distance FROM jos_bid_auctions a INNER JOIN zipcodes z ON (a.zipcode=z.zipcode) HAVING distance < ".$distance." ORDER BY distance ASC"; ?>
  20. Agreed, but how do you know the amount of memory required for a task? I would also agree that performance has nothing to do with syntax, but still it seems to perform much better at system tasks. Maybe the size of PHP's library and the number of compiled extensions is much larger than PERL reducing parse time. I'm only guessing here now.
  21. That is completely crazy and would result in expensive queries. Your best solution is to use latitude & longitude (Haversine Formula) values to return items in a given distance from a point of origin.
  22. It is PERL, not pearl! (Practical Extraction Report Language) There are no beneifts unless you state what you are using it for! It's like saying to get from A to B what are the benefits of a Ferrari over a Ford. Well there are none, however if you ask the same question stating you are on a race track then there is a definitive answer. For dynamic websites, PHP has to be the preferred choice (as this is a php forum few will disagree). However for server scripts performing operations such as database/filesystem backup, working with extremely large amounts of data in files, ftping to remote storage then I look to PERL. Not 100% sure but I think it performs faster and have never seen any memory allocation warnings when working with massive amounts of data like in php.
  23. What the hell are you on about at all? Absolutely
×
×
  • 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.