Harker |
|
---|---|
Hello to all, I created a plugin which allows me to see the status of the streams of my members. It works very well but I do not manage to have that I want in spite of my nights white and my liters of coffee. At present, my page shows all the on-line and off-line streams. I would need your help so that my plugin shows only the on-line streams.
PHP $sql = $db->query("SELECT * FROM cot_streams"); while ($data = $sql->fetch()) { $data['teststream'] = '<a class="ltwitch" href="#" data-tnick="'.$data['streams_name'].'">'.$data['streams_name'].'</a> (<span>...</span>)'; $t-> assign(array( 'STREAMS_ID' => $data['id'], 'STREAMS_USER_ID' => $data['userid'], 'STREAMS_USER_TWITCHNAME' => $data['teststream'] )); $t->parse('MAIN.STREAM_ROW'); } TPL <!-- BEGIN: STREAM_ROW --> <div>{STREAMS_ID}</div> <div>{STREAMS_USER_ID}</div> <div>{STREAMS_USER_TWITCHNAME}</div> <!-- END: STREAM_ROW --> JS jQuery(document).ready(function ($) { $('.ltwitch').each(function () { var tnick = $(this).data('tnick'); var span = $(this).next(); $.getJSON("https://api.twitch.tv/kraken/streams/" + tnick + ".json?callback=?", function (c) { if (c.stream == null) { span.html("Offline"); } else { span.html("Online"); } }); }); });
PLLLLeeeeeaaassseeee Help me to transform my nightmares, I do not sleep any more ^^ |
Twiebie |
|
---|---|
I think you need to re-arrange your code a bit as you are now parsing all streams to the TPL regardless of if they are online or not. Here's an example without the use of JS: $sql = $db->query("SELECT * FROM cot_streams")->fetchAll(); if ($sql) { foreach ($sql as $data) { $json = file_get_contents('https://api.twitch.tv/kraken/streams/'.$data['streams_name']); $stream = json_decode($json); if ($stream->stream) { $t->assign(array( 'STREAMS_ID' => $data['id'], 'STREAMS_USER_ID' => $data['userid'], 'STREAMS_USER_TWITCHNAME' => $data['teststream'] )); $t->parse('MAIN.STREAM_ROW'); } } }
|
Harker |
|
---|---|
I modified my code with your and now it works marvelously !! One very very thank you for your help :) |
Twiebie |
|
---|---|
You're welcome! |