Jump to content

yuckysocks

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

yuckysocks's Achievements

Member

Member (2/5)

0

Reputation

  1. I did indeed; that's actually at the root of the foreach loop. Good suggestion though. Anyone else have any ideas?
  2. Hi all. I'm trying to get data into a form that works with flot, the jQuery graphing library. I need to get UTC timestamps from Twitter into a javascript timestamp (=Unix timestamp * 1000). My code currently looks like this: foreach($decoded['results'] as $currentResult) { if($currentResult['from_user'] == $user) { $strippedTexts = $currentResult['created_at']; $bignumber = strtotime($strippedTexts); $biggerstring = bcmul($bignumber, 1000); $dates []= settype($biggerstring, "int"); } } This creates a dates[] array that contains the value "1", once. Clearly not what I want. I've tried multiplying by 1000 (resulted in a large number barf: -2147483648), multiplying by 1000.0 (to convert to a float, maybe it would take a bigger number). I've also tried concatenating "000" and using setype($var, "float") and that won't work either. Any idea how I can get the incoming array of UTC time stamps into "milliseconds since 1970" (which is what the flot library needs, as an integer, not a string)? If it helps, here's the entire code, soup to nuts: <?php $url = "http://search.twitter.com/search.json?q=%23runlogger"; $contents = file_get_contents($url); $decoded = (json_decode($contents, true)); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" src="jquery.flot.js"></script> </head> <body> <form name="input" action="skeleton.php" method="get"> Twitter Username: <input type="text" name="user" /> <input type="submit" value="Go Get 'em, Tiger" /> </form> <?php if (isset($_GET['user'])) { $miles = array(); $dates = array(); $pairs = array(); $user = $_GET["user"]; foreach($decoded['results'] as $currentResult) { if($currentResult['from_user'] == $user) { $strippedTexts = explode(" ", $currentResult['text']); $miles []= $strippedTexts[0]; } } foreach($decoded['results'] as $currentResult) { if($currentResult['from_user'] == $user) { $strippedTexts = $currentResult['created_at']; $bignumber = strtotime($strippedTexts); $biggerstring = bcmul($bignumber, 1000); $dates []= settype($biggerstring, "int"); } } foreach($miles as $key=>$mile) { $pairs[$dates[$key]] = $mile; } ksort($pairs); foreach($pairs as $d=>$m) { $orderedpairs .= "[$d, $m], "; } echo " <div id='placeholder' style='width:600px;height:300px'></div> <script language='javascript' type='text/javascript'> $(function () { var data = [[$orderedpairs]]; var plotarea = $('#placeholder'); var options = { legend: { show: true } xaxis: { mode: time } } $.plot( plotarea , data , options ); }); </script> $orderedpairs "; } else { echo "Go ahead and search for a name! Try 'Tester2314' to see what an example could look like"; } ?>
  3. Hi there, I just got a project to work, and want to know where I could have improved the code. Thanks for taking a look: This is a Cron every hour and sets up the database: <?php // displays all the file nodes $xml=simplexml_load_file('http://www.weather.gov/xml/current_obs/KBOS.xml'); if ($xml) { //sets up all the variables I need for the SQL addendum $weather = $xml->weather; $temp = $xml->temp_f; $wind = $xml->wind_mph; $date = $xml->observation_time; } //error catching else { echo "Oops, bad input"; } $db = mysql_connect('blah, blah, blah') or die(mysql_error()); mysql_select_db('table') or die(mysql_error()); mysql_query("INSERT INTO weatherdata (date, weatherstr, temp, wind) VALUES ('$date', '$weather', '$temp', '$wind')"); mysql_close($db); ?> And the next part fetches the data I want and makes it as 45, 48, 59, 64.... for the last 35 values. <?php //open connection $db = mysql_connect(blah, blah, blah) or die(mysql_error()); mysql_select_db('tables') or die(mysql_error()); $result = mysql_query("SELECT * FROM weatherdata ORDER BY id DESC LIMIT 35"); $row = (mysql_fetch_array($result)); while($row = (mysql_fetch_array($result))){ $output[] = $row['temp']; } $reverse = (array_reverse($output)); $csv = implode(", ", $reverse); ?> I want to know if this leaves memory open, if I could have done this more elegantly, or anything like that. I have the FUNCTION down, now I'm worried about learning good FORM. Thanks! -Alex
  4. Hello. I have a query, and I want the results eventually to be variables that I serve to a JS library to make graphs. I have this currently: $result = mysql_query("SELECT * FROM weatherdata ORDER BY id DESC LIMIT 10"); $row = mysql_fetch_array($result) or die(mysql_error()); $row2 = array_reverse($row); foreach($row2 as $a){ echo $a."<br />"; } The table is 5 fields (including the key ID). The returned output is only the most recent entry, twice! 18<br />18<br /> 13<br />13<br /> 51<br />51<br /> Mostly Cloudy<br />Mostly Cloudy<br /> Last Updated on Mar 14, 4:54 pm EDT<br />Last Updated on Mar 14, 4:54 pm EDT<br /> With the actual DB entry looking like this: ID = 18 Wind = 13 temp = 51 weatherstr = Mostly Cloudy date = Last updated on Mar 14, 4:54 pm EDT I don't know why it only shows the most recent entry (DB has >50 entires so far, it's populated hourly), nor why it's shown twice. What I'm looking for, eventually, is to query the 10 most recent entries, and set the "temp" result for each as a variable ($a, $b, $c...) and then feed those variables to a JS library to make a graph. Any suggestions would be helpful!
  5. it was on 27, and with a different editor, I found some weird errors. I copied/pasted from a website, but something that showed up as a space in the browser was actually encoded as a weird E`. Hard to find!
  6. Easy fix, no doubt: $db = mysql_connect('xxxxx.xxxxxx.net','xxxxxx','xxxxxxxxxxx') or die(mysql_error()); mysql_select_db('xxxxxxxxxxxxx') or die(mysql_error()); mysql_query("INSERT INTO weatherdata (date, weatherstr, temp, wind) VALUES ('$date', '$weather', '$temp', '$wind')"); mysql_close($db); Unexpected T String Error. Gah! I don't THINK I have a syntax error, but of course, no one ever does...
  7. That's all I needed to hear. Thanks for the help.
  8. ok, so here is the code I have: Blah <?php // displays all the file nodes if(!$xml=simplexml_load_file('http://www.weather.gov/xml/current_obs/KBOS.xml')){ trigger_error('Error reading XML file',E_USER_ERROR); } $weather = $xml->current_observation->weather; echo $weather; ?> When I load up the page (not locally, for what it's worth) it only displays "Blah", not even the error specified. Can I not use the simplexml_load_file function on remote files? I know fopen works remotely... but that's not what I really want to do. Suggestions?
  9. Hi all, I'm enjoying learning myself, but want to make sure my big picture steps are efficient for this project: I want to make a running http://sparkline.org/ of "good" weather vs. "bad" weather in my area. This will look at a federal XML file once a day with a cron job, parse the data, store it to my own database, then query the previous 10 entires in the DB to create the sparkline. Is this a reasonable way to execute this project? Also, I'm at the point where I can import the xml stream, but am not sure the best way to get at it. Xpath queries? Can't some function turn it into an array? I'm not so good at these things, so any hints would be great. Thanks!
  10. hrmm. at -least a semi colon. (isn't it always a semi-colon?) but that still dumped out the errors. I don't know much about the functions (it's a hello world example, after all) file_handle looks like a variable, so I tried it with a $ in front: while (!feof($file_handle)); but that didn't reply with -anything- still stumped!
  11. Hi there. Running examples from a webbots book. Here's the code: <? $target = "http://www.schrenk.com/nostarch/webbots/hello_world.html"; $file_handle = fopen($target, "r"); #fetch the file while (!feof(file_handle)) echo fgets($file_handle, 4096); fclose($file_handle); ?> I ran it from terminal on OS X 10.5 (FWIW) and it spat back infinite lines of: Warning: feof(): supplied argument is not a valid stream resource Instead of the expected line-by-line response from the targeted web server. It DOES show the source HTML after each error message, but when the source is done, the errors continue to infinity and I have to close Terminal. I'm a PHP newbie, so go ahead and talk down to me Thanks for explaining what's happening, Alex
  12. Yes, Yes, 1000 times yes. It's amazing/frustrating/thrilling when just two characters make a script work or not work. Thanks for the continued help and support. Topic Solved.
  13. Unfortunately, the second header is still displayed as text at the start of the email (the text/html char encoding one). Any other ideas? This is not a huge deal, but I want the resulting email to be as useful as possible to the recipient (ie, just click a link instead of copy/paste it in). Thanks again for the help, Alex
  14. I implemented Craygo's code. The variable is converted to the proper word, but the second header (Content-Type: text/html; charset=ISO-8859-1) is just displayed, as opposed to being used as a header. This prevents the link from being converted into a proper anchor element. Thoughts? Thanks so much, Alex
  15. Hi, I'm looking to get this function to work: mail('them@gmail.com', 'A new case study has been posted!', 'Go to <a href="admin.php">the admin page</a> to look it over. It is information regarding $schoolname', 'From: me@gmail.com'); The mail gets sent properly, but the link and the variable aren't treated properly. The message is in fact going to gmail, so maybe it has something to do with how they treat html in messages, but at least the variable ought to get filled in, eh? It's a POSTed variable, do I need to call it that? Anyhow, thanks for your always prompt help. Alex
×
×
  • 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.