Jump to content

Texan78

Members
  • Posts

    272
  • Joined

  • Last visited

Everything posted by Texan78

  1. I am not sure if I am understanding your question. I thought I stated what I am having a problem with. I may not be using the correct wording. What I am trying to do is search through the JSON file and if any of the "streamStatus" is true then show a certain message, if false show a different one. What I am having a problem with is I am not sure how to search through all of the "streamStatus" from the multiple response from the JSON file to check if any of them are true. Would it be easier if I just connected to the DB and looped through them? If so how would I go about doing that. include('dbconn.php'); $sql = "SELECT StreamStatus FROM streamdb";$result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row $i = 1; while($row = $result->fetch_assoc()) { $status[$i] = $row["StreamStatus"]; $i++; } } // Lets assembly the banners to display $notifyOffline = '<div class="alert alert-danger" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently no active chasers online streaming at this time.</div>'; $notifyOnline = '<div class="alert alert-success" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently X chasers streaming LIVE... </div>'; if ($status[$i] == "true") { echo $notifyOnline; } else { echo $notifyOffline; }
  2. I Also don't need to use the JSON file. If need be I can just create a file that connects to the DB and searches that column to check if any of them are true and if so then echo a certain message. If they are all false then echo a different message.
  3. Hello, I have this JSON response that has streamStatus": "false", as one of the variables. There is 6 total entries on this. Here is an example of two. { "streamers": [ { "DisplayName": "Nick Copeland", "StreamKey": "ncopeland", "StreamURL": "rtmp://strsvr-01.dfwstormforce.com/live/", "gpsStatus": "false", "UserLat": "N32.97353", "UserLon": "W96.71433", "UserHeading": "none", "UserLocation": "2 miles NNE of downtown Richardson, Texas", "streamStatus": "false", "CurrentViewers": 0, "TimeStamp": "2016-10-24 11:36:29" }, { "DisplayName": "Kevin Saunders", "StreamKey": "ksaunders", "StreamURL": "rtmp://strsvr-01.dfwstormforce.com/live/", "gpsStatus": "false", "UserLat": "N30.43435", "UserLon": "W87.20219", "UserHeading": "none", "UserLocation": "", "streamStatus": "true", "CurrentViewers": 0, "TimeStamp": "2016-10-24 11:36:56" }, I have a code that works great for a single JSON response but, what I am trying to do is search through the JSON response of that file and if any one of the "streamStatus" is true then show a certain message then show a different message if false. Where I am stuck is I am not sure how to search through them all. <?php $jsonPath = "http://stream.dfwstormforce.com/inc/api.php"; // URL to json data // Lets get and parse the data and create the variables $json_string = file_get_contents($jsonPath); $parsed_json = json_decode($json_string, true); $status = ($parsed_json['streamers']['streamStatus']) ? 'true' : 'false'; var_dump($status); // Lets assembly the banners to display $notifyOffline = '<div class="alert alert-danger" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently no active chasers online streaming at this time.</div>'; $notifyOnline = '<div class="alert alert-success" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently X chasers streaming LIVE... </div>'; if ($status == "true") { echo $notifyOnline; } else { echo $notifyOffline; } ?>
  4. I got it sorted with this solution and seems to work great and is lightweight. <?php $pdo = new PDO('mysql:dbname=_streamdb;host=localhost;','root','password', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); $result = $pdo->query('SELECT DisplayName, StreamKey, StreamURL, gpsStatus, UserLat, UserLon, UserHeading, UserLocation, UserLocation, streamStatus, CurrentViewers, TimeStamp FROM maintable'); $rows = $result->fetchAll(PDO::FETCH_ASSOC); header('Content-Type: application/json;charset=utf-8'); echo json_encode(['streamers' => $rows], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK); ?>
  5. Hello, I am trying to query a MySQL database to output it in a JSON format without having it write to a new file I.E. file.json. I can create a script that creates a json array but, I need the output in a JSON format. The script I have been working with below connects to the DB but, it is not populating with data. It just gives me this output. I added the DB connection check to check if the script was connecting to the DB. This is the code I am currently working with. Is there anyone who could tell me what I am missing and could improve on. DB info removed for security reasons. <?php header('Content-type:application/json;charset=utf-8'); //Make connection to database $db=new PDO('mysql:dbname=streamdb;host=localhost;','root',''); // Check connection if ($db->connect_error) { die("Connection failed: " . $db->connect_error); } echo "Connected successfully"; //Prepare the query for analyzing $sql=$db->prepare('select * from maintable'); $response = array(); $streamers = array(); $result=mysql_query($sql); while($sql=mysql_fetch_array($result)) { $displayname=$row['DisplayName']; $streamkey=$row['StreamKey']; $streamers[] = array('DisplayName'=> $displayname, 'StreamKey'=> $streamkey); } $response['streamers'] = $streamers; echo stripslashes(json_encode($response)); ?> -Thanks!
  6. I got it sorted out by using this below. I am not sure if this is the correct method but, it works. I think because it is an addon domain and the files are in a sub-domain of the add on domain the normal method doesn't work as normal I am assuming. <?php include($_SERVER['DOCUMENT_ROOT'].'/network/kdfw/inc/chaserData.php'); ?>
  7. Thanks, I have tried that too with my many combinations. That does not work ether. This is the error I get in the error log trying the above suggestion. I am not sure if this is because it is in a sub-domain or what but I am having all kinds of trouble using include statements. Even in my dbinfo.php file I use in my script that calls data from a MySQL I had issues and had to use ($_SERVER['DOCUMENT_ROOT'] before that include statement to even get that to work. Anyways, here is the error from using the suggestion you mentioned.
  8. I am having some problems with an include statement. Seems like a very simple task but, for some reason probably due to lack of knowledge it isn't working. Here is the layout of the folder structure I am working with for example. The pages are in a sub-domain. Sub-domain is called media. The index page is in media > network > kdfw > index.php The index.php is the file in which I am trying to include the file in. The included file is in media > network > kdfw > inc These are the methods I have tried... <?php include '/media/inc/chaserData.php'; ?> <?php include 'media/inc/chaserData.php'; ?> <?php include '/inc/chaserData.php'; ?> <?php include 'inc/chaserData.php'; ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'/media/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'media/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'/inc/chaserData.php'); ?> <?php include ($_SERVER['DOCUMENT_ROOT'].'inc/chaserData.php'); ?> None of the above work and I am not sure as to why. Is there anyone who could provide some insight and shed some light to this issue? -Thanks
  9. I appreciate your response but, I do not appreciate the sarcastic remarks I am receiving when it is not deserving. I do not work with PHP but a couple times a year if that. So I could do without the ridicule. A much better approach instead of demeaning people would be to guide them. That is why this is a community support forum. For those looking for support on issues in which they are stuck on. Not to be laughed at for the lack of proficient PHP knowledge. As I stated in my OP.... $status also comes from the database with a value of ether true or false. Therefore if $status = true then echo blah blah blah. If I am doing this incorrectly could someone please provide me with a better and correct approach as I am only going off memory and my searches are coming up empty. -Thanks!
  10. Huh? I am sorry, I only speak English.
  11. Well, come to find out this isn't working after all. <?php if ($status[2] < true) { echo "<span class='label label-success'>LIVE</span>"; } else { echo "<span class='label label-important'>OFFLINE</span>"; } ?>
  12. I am sure I am having a brain fart and just need some extra eyes as I am overlooking something. I am trying to do a very simple IF statement but, for some reason it is not working. Here is what I have. <?php if ($status[1] < true) { echo $location[1]; } ?> I have also tried it this way and it won't work ether. <?php if ($status[1] < true) echo $location[1]; ?> I am using that same $status variable in a different ELSE/IF statement and it works fine but, for some reason it is not working for this. Logic behind how this is suppose to work. This is pulling from a database and I can echo the $location variable just fine so I know that is working. $status also comes from the database with a value of ether true or false. So what I am trying to do is if the $status value is true then echo $location which is just the location which is in the DB. For some odd reason which I am sure it is something simple I am overlooking, it is not working. If anyone could offer my tired eyes some input that would be greatly welcomed. -Thanks
  13. I hate javascript and working with Google maps but, anyways. I am trying to update my old maps to a new style. Here is the new style. http://www.mesquiteweather.net/lsm/map.html I am trying to added the markers to the map from an XML file which is this one. http://www.mesquiteweather.net/tracker/data.xml It should look like this. http://www.mesquiteweather.net/wxspotter.php I have transferred the code over to the updated map style but, for some reason it isn't displaying the markers. Can someone please tell me what it is I am missing or doing wrong which I am sure is a lot since I am horrible with javascript. Here is the code to the updated map that I am trying to show the XML markers on. http://pastebin.com/rFVG4nJS -Thanks
  14. Yes it is possible that it could contain more than one element. What will I do multiple items in the array? Hopefully ignore them. For what I am trying to do right now I just need the name and hopefully I can use that as a value to trigger a true or false so I can show online or offline. This XML file doesn't leave much to work with. I wish it had an active key under a certain element for a user like the old one had but, it does not. I don't need the value of [name] persay, but rather use that as if that value exists then true if not false. Is something like the possible? -Thanks
  15. Hello, I will try to keep this short and sweet. This small script I have the data source has changed and I need a way to trigger an online and offline tag. Which was really easy with how the JSON data file was set up before. Now things are a little more complicated and I am not sure how to approach this. Here is the code I am working with that needs to be updated. I need to change out where the $status varible is to use the [name] key and if there is a value then show as online. If it is empty or doesn't exist show as offline. As this key isn't a normal true false value how can I approach this so that if the key has a value then set as true? // Lets get and parse the data and create the variables $json_string = file_get_contents($jsonPath); $parsed_json = json_decode($json_string); $status = ($parsed_json->active) ? 'true' : 'false'; // Lets assembly the banners to display $online = '<span class="label label-success"> ONLINE</span>'; $offline = '<span class="label label-danger"> OFFLINE</span>'; if ($status == "true") { echo $online; } else { echo $offline; } Here is a sample of the JSON file which was XML that I have parsed to JSON to get the keys. I need to get to the [name] and if there is a vaule set as true. Hopefully this makes sense. I can't find anything that talks about this but, then again. I am really not sure how to word it or what exactly I am looking for. Array ( [0] => Array ( [name] => live [live] => Array ( [stream] => Array ( [name] => rcontreras [time] => 2969160 [bw_in] => 342512 [bytes_in] => 186226066 [bw_out] => 533112 [bytes_out] => 285996865 [bw_audio] => 0 [bw_video] => 342512 [client] => Array If anyone can offer some assistance that would be great! This has been bothering me for weeks. -Thanks
  16. Thanks, yeah you are right. I noticed that after the fact. That is where I am stuck is I need to pull just that data but keep it together from each line. My brain is fried at the moment from trying to remember how to use this all over again. ## Start Configurable data ## //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## $xml = simplexml_load_file($data); //Set initial output to false foreach($xml->spotter as $spotter) { $name = $spotter['name']; $lat = $spotter['lat']; $long = $spotter['lng']; );
  17. Hello, I am the Senior Project Manager for an established web site that is looking to add a new live streaming feature to our site. We have most of the section laid out for demo purposes. Background, we will be streaming live storm chases. The streaming server is already set up and is solid but, if you have experience in NGINX RTMP MODULE that is a plus. It is running on a VPS and is up and running but might need some tweaking. The main thing we are needing is someone one is very fluent working with PHP and Javascript. 3-5+ experience. Working with Google Maps is a must as well. Possible MySQL DB experience may be needed to complete this project. What we are needing. We have two separate pages. One is a video wall that will show all the active streams. We are looking for someone who can parse the XML file from the NGINX streaming server and dynamically show the active player. We are using JWPlayer for this to show the streams which is self hosted. Then when the stream is over it goes away. This will probably need to be updated with JQuery but update it so it does not update the entire page and cause the other current streams to stop. It will need to show their name and location in the header of the div container. Right now they are just statically placed. We only need the wall to show active streams only. The containers and players are already set up. We need someone to make them dynamic and only show the active streams. Second is a Google Map. We have a data feed that will show users locations on a map. We have the base map built on Google Maps V4. We currently have a working example using V3. If you can port over the locations from the data feed from the V3 map that would be great or write something from scratch. Also we need to place the persons player in the info box when someone clicks on their icon on the map with the name and location above the player. The data feed we have for the peoples location needs to only show certain people from that data feed. We have all the data feeds to work with and we run the streaming servers. We just need someone who can tie in the loose ends and do the back end heavy lifting as we are on a short time frame. For example of the pages and more information please send me a PM and I can give you more information. Please provide in your PM your experience and possible demo work you have done in the past as well as an initial quote. -Thanks
  18. Hello, I am look for some assitence on a project I am working on. It has been a couple years since I have done something like this and I know it is easy to do as I have done it before but, I have forgot some of it. I am trying to parse this feed http://www.spotternetwork.org/data.php and create variables for the lat, lng and name so I can plot them on a Google Map V4. I do not think I am going about this the right way since those are child nodes and I have completed forgot out to use DOM which I think that is what I need to be using. Right now I am just trying to get it parsed and go from there. Also I need the lat lng to coincide with the name. ## Start Configurable data ## //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## $xml = simplexml_load_file($data); //Set initial output to false $tData = false; foreach($xml->spotter as $spotter) { $name = $spotter['name']; $lat = $spotter['lat']; $long = $spotter['lng']; echo $spotter; Any help would be greatly appreciated. -Thanks
  19. Would this be correct then for displaying the message per the code you supplied? It works but, just want to make sure the if statement is the correct way. BTW, thank you for your help. $message = ''; // default to an empty string for the result foreach($alertValues as $value){ // loop over the $alertValues array if(in_array($value,$events)){ // checking if each value in turn is in the $events array $message = $value; // a match was found, save it as the result break; // stop on the first match } } //Display weather radio banner if alert is found if($message) { echo '<div style=' . $bannerStyle . '> <strong>WEATHER BROADCAST ALERT - ' . $message . '</strong>... Dallas County, listen now to our LIVE NOAA Weather Radio Stream <a href=" ' . $feed . '" class="NWRLink" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County">[Click here to listen]</a></div>'; } I am not sure what you were referring to but did you mean the $alertValues array? While it may have been incorrect, it was working and pulling the highest alert at the time which wasn't the last event added. Before when it was looping through all of them it was showing 5-6 different banners at the same time instead of just one, the one being the highest as I wanted. The highest being Severe Thunderstorm Warning and lowest being Flood Warning at that time. Once I used the first code I had put together it worked and only showed one banner as I wanted to and it was Severe Thunderstorm Warning, once that expired it showed the next highest one which was Tornado Watch, then once it expired, it showed the next lowest one which was Flood Warning. So it was working, the logic may have just not been correct. Since I don't know the difference, if it works, I assume it's correct. Which is why I asked if it was correct. I do appreciate your help.
  20. Well, after playing with it some more this is what I did and it seems to be working. I am not sure if this is right but, it is working at the moment. // Lets assembly the banners to display if (in_array($event->nodeValue, $alertValues)) { echo '<div style=' . $bannerStyle . '> <strong>WEATHER BROADCAST ALERT - ' . $message . '</strong>... Dallas County, listen now to our LIVE NOAA Weather Radio Stream <a href=" ' . $feed . '" class="NWRLink" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County">[Click here to listen]</a></div>'; }
  21. YES!, That is exactly what I am needing but, how would that work exactly? How would I set up the in_array()? This is what I have come up with but, it's not working so I know I am doing something wrong. According to the examples I have read this should work. The in_array() is at the bottom of the code. //Set path to data file #$data = "http://alerts.weather.gov/cap/".$zone.".atom"; $data = "http://alerts.weather.gov/cap/wwaatmget.php?x=".$zone."&y=1"; ## End Configurable data ## $alertColor = ' '; $alertText = '#FFF'; $event = ' '; // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // Lets parse the feed $dom = new DOMDocument(); $dom->load($data); $events = []; foreach ($dom->getElementsByTagNameNS("urn:oasis:names:tc:emergency:cap:1.1", "event") as $event) { $events[] = $event->nodeValue; } $alertValues = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flood Warning', 'Flash Flood Watch', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); $events = array_intersect($alertValues, $events); // Set the alert colors for the banner background switch($event->nodeValue) { case 'Tornado Warning': $alertColor = 'rgba(255, 0, 0, 0.4)'; break; case 'Severe Thunderstorm Warning': $alertColor = 'rgba(255, 165, 0, 0.4)'; break; case 'Tornado Watch': $alertColor = 'rgba(255, 255, 0, 0.4)'; break; case 'Severe Thunderstorm Watch': $alertColor = 'rgba(219, 112, 147, 0.4)'; break; case 'Flash Flood Warning': $alertColor = 'rgba(139, 0, 0, 0.4)'; break; case 'Flash Flood Watch': $alertColor = 'rgba(46, 139, 87, 0.4)'; break; case 'Flood Warning': $alertColor = 'rgba(0, 255, 0, 0.4)'; break; case 'Flood Watch': $alertColor = 'rgba(46, 139, 87, 0.4)'; break; case 'Flood Advisory': $alertColor = 'rgba(0, 255, 127, 0.4)'; break; case 'Winter Storm Warning': $alertColor = 'rgba(255, 105, 180, 0.4)'; break; case 'Winter Storm Watch': $alertColor = 'rgba(70, 130, 180, 0.4)'; break; case 'Winter Weather Advisory': $alertColor = 'rgba(123, 104, 238, 0.4)'; break; case 'Special Weather Statement': $alertColor = 'rgba(255, 228, 181, 0.4)'; } // Lets assign some styles for the banner $bannerStyle = '"color:' . $alertText . '; width:100%; border-top-style:solid; border-bottom-style:solid; border-color:#FFF; border-width:1px; font-size:12px; text-shadow: 0 1px 1px #111; font-weight:700; font-family: Arial,Helvetica,sans-serif; text-align: center; background-color:' . $alertColor . '; margin-bottom:5px; padding: .2em 0em .2em 0em"'; // Lets assembly the banners to display if (in_array($events, $alertValues)) { echo '<div style=' . $bannerStyle . '> <strong>WEATHER BROADCAST ALERT - ' . $message . '</strong>... Dallas County, listen now to our LIVE NOAA Weather Radio Stream <a href=" ' . $feed . '" class="NWRLink" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County">[Click here to listen]</a> </div>'; }
  22. The problem isn't the color anymore. I have gotten that sorted. What I can't seem to resolve is for it to only show one single entry from the array and not loop through all of it and display everything it is able to match from the RSS feed it is parsing. I just need to display a single entry by priority which is set in the array. In case it was missed above, here is the array and this is the order in which a SINGLE entry should display if the rss contains this. At this time, it will display multiple entries if it is contained in the rss feed which I don't want, only a single entry set by it's priority. $alertValues = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flood Warning', 'Flash Flood Watch', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement');
  23. I have done a lot of searching of how I can loop through this array and only display a single entry from the array if one of those values exsist in the RSS feed. How can I do this without using foreeach? Otherwise it works great, I just only need to display one and it is the one with the most priority and the priority is set by the order they are listed in the array. How can I accomplish this? -Thanks
  24. Disregard this post. I found an alternative method. Created a php script on my server that parses the XML file then call it internally from the program using the remote file option and it works great.
  25. Hello, first let me say I am HORRIBLE with Javascript. I am using this program called Xsplit for live streaming. It has the ability to add the title from an RSS feed. That is great but, I would also like to add another node called "summary" and I will be honest, I have no clue after trying several things and searching the net. Here is the script it uses. /* This shows title of RSS feed entries from [RSS_FEED_URL] each item sepated by "||", number of entries shown can be specified using the [NUMBER_OF_ENTRIES] variable. This only checks for feed once (on scene load) */ /** * @name RSS_FEED_URL * @label RSS Feed Url * @type text */ var RSS_FEED_URL = "http://alerts.weather.gov/cap/wwaatmget.php?x=TXZ119&y=1"; /** * @name NUMBER_OF_ENTRIES * @label Number of Entries * @type spinner * @min 1 * @max 20 * @step 1 * @description Values, 1-20 */ var NUMBER_OF_ENTRIES = 8; /*Do not modify anything below*/ scriptLoading(); function scriptLoading(){ var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = "http://www.google.com/jsapi"; newScript.onload = initial; headID.appendChild(newScript); } function initial(){ google.load("feeds", "1", {"callback" : initialize}); } var CombinedEntries=""; var initialize = function() { var feed = new google.feeds.Feed(RSS_FEED_URL); feed.setNumEntries(NUMBER_OF_ENTRIES); feed.load(function (result) { if (!result.error) { var container = document.getElementById("feed"); var entries = new Array(); var i=0; for (; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; entries[i] = entry; CombinedEntries=CombinedEntries+" || "+entry.title"; } SetText(CombinedEntries, "RSS Feed Reader: " + RSS_FEED_URL); } }); }; if (smlTitleTimeouts && smlTitleTimeouts != null) clearTimeout(smlTitleTimeouts); This line adds the title, that much I can tell. CombinedEntries=CombinedEntries+" || "+entry.title"; If I try to add another line but change title to summary it comes back undefined. So how could I add another another node. Both title and summary are both under the same parent node which is "entry". I would just like to add "summary" to this as well but not sure how. Can anyone help me out? -Thanks
×
×
  • 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.