Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [23-Sep-2017 20:04:17 UTC] PHP Notice: Undefined variable: results in /home/harabla/public_html/testi/update.php on line 46
- <?php
- $servername = "myserver";
- $username = "user";
- $password = "pass";
- $dbname = "dbname";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = mysqli_query($conn, "SELECT id from users");
- $userinfo = array();
- while ($row_user = $sql->fetch_assoc())
- $userinfo[] = $row_user;
- foreach ($userinfo as $user) {
- $url = "http://www.pdga.com/player/".$user['id'];
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $html = curl_exec($ch);
- curl_close($ch);
- $dom = new DOMDocument();
- @$dom->loadHTML($html);
- $xpath = new DomXPath($dom);
- $class = 'current-rating';
- $divs = $xpath->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]");
- foreach($divs as $div) {
- preg_match('/Current Rating:s+(d+)/', $div->nodeValue, $results);
- }
- if (!is_null($results[1])){
- $sql = "UPDATE users SET rating=$results[1] WHERE id =".$user['id'];
- } else {
- $sql = "UPDATE users SET rating='0' WHERE id =".$user['id'];
- }
- if ($conn->query($sql) === TRUE) {
- echo "Record updated successfully <br>";
- } else {
- echo "Error updating record <br> " . $conn->error;
- }
- unset($results);
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement