rivacom Posted March 10, 2014 Share Posted March 10, 2014 So in a nutshell, what I'm trying to do is query our website, grab players Twitch usernames, and scan them through the Twitch API to see if their online or not. If they are, it takes their usernames and viewer count and stores them in a new table. This will be setup to run every 5 minutes. However... with 1 user it runs great, with more then one... I get the same viewer count for each user. Plus it's taking offline users as well. Any advice would be great! Thanks. <?php // Upload to Database $con=mysqli_connect("localhost","username","password","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $deletetable = $con->prepare('TRUNCATE TABLE twitch_streams'); $deletetable->execute(); $deletetable->close(); if ($result = $con->prepare("SELECT field_value FROM xf_user_field_value WHERE field_id = 'twitch' AND field_value != ''")) { $result->execute(); $result->bind_result($twitchfield); $result->store_result(); while($result->fetch()) { $data = json_decode(file_get_contents('http://api.justin.tv/api/stream/list.json?channel=' . $twitchfield)); $viewer[] = $data[]->channel_count; if ($data[]->stream != NULL){ if ($insert = $con->prepare("INSERT INTO twitch_streams (twitchuser, viewercount) VALUES (?, ?)")){ $insert->bind_param('si', $twitchuser, $viewercount); $twitchuser = $twitchfield; $viewercount = $viewer[]; $insert->execute(); echo $twitchfield; echo $viewercount; $insert->close(); } } else { printf("Prepared Insert Statement Error: %s\n", $con->error); } } } else { printf("Prepared Statement Error: %s\n", $con->error); } mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
rivacom Posted March 12, 2014 Author Share Posted March 12, 2014 Still hoping to find some help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.