-
Posts
3,584 -
Joined
-
Last visited
-
Days Won
3
Everything posted by JonnoTheDev
-
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.
-
[SOLVED] Select option value form, more than one value
JonnoTheDev replied to select's topic in PHP Coding Help
$x = "13,2"; $vals = explode(",",$x); $articleId = $vals[0]; $pictureId = $vals[1]; -
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.
-
Agreed
-
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)) { } ?>
-
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(); } ?>
-
yes, is the day field a unix timestamp?
-
No it wont. Are you sure the correct keys are used? $results['valid'] $results['invalid']
-
Also displaying data using the DOM from AJAX requests makes it difficult to scrape.
-
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
-
[SOLVED] Select option value form, more than one value
JonnoTheDev replied to select's topic in PHP Coding Help
Bad syntax echo "<option value='".$row['ii'].",".$row['bi']."'>".$row['io']."</option>\n"; -
<?php print "Valid Entries ".count($results['valid'])."<br />"; print "Invalid Entries: ".count($results['invalid']); ?>
-
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>
-
So for John Doe you would divide 100 by 95 to give you 1.05263 for assignment 1 and display it how?
-
Need help: how to catch acess of undefined class properties
JonnoTheDev replied to baman's topic in PHP Coding Help
Use the same for your getter. Make sure you handle your exceptions gracefully. -
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.
-
[SOLVED] Need a smart query. Next 12 results
JonnoTheDev replied to Skipjackrick's topic in PHP Coding Help
Search the forum for paginating results. Your pagination could consist of 2 links, 'prev 12', 'next 12' -
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.
-
Need help: how to catch acess of undefined class properties
JonnoTheDev replied to baman's topic in PHP Coding Help
absolutely -
Need help: how to catch acess of undefined class properties
JonnoTheDev replied to baman's topic in PHP Coding Help
Please note: requires php >= 5.1 <?php $x = new Objekt(); if(property_exists($x, 'baz')) { $x->baz = 9; } else { print "property does not exist"; } ?> -
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"; ?>
-
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.
-
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.
-
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.
-
What the hell are you on about at all? Absolutely