Jump to content

fez

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by fez

  1. Ooooh. I have just tried this code instead: $postcode = $geodata['town_city']; $requestAddress = "http://www.google.com/ig/api?weather=,,," . $postcode; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); And it works! (note the data being retrieved is now the town/city). Although this is great, it is not as accurate as the postcode/zipcode. I suspect this may be because of the space in the postcode? Is there a way to remove the space before declaring? Thanks
  2. Hi, I did post a question earlier but have now perhaps narrowed the problem and am still having trouble! I'm still learning PHP by working on a personal project. I'm having an issue accessing an xml file. If I use the following code I get a 'String could not be parsed as XML' error yet if I remove the $postcode variable when defining the $requestaddress variable and extend the url manually it works! $postcode = $geodata['postcode']; $requestAddress = "http://www.google.com/ig/api?weather=,,," . $postcode; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); Any suggestions greatly appreciated.
  3. Thanks. I tried what you said and it now throws this error: Warning: file_get_contents(http://www.google.com/ig/api?weather=,,,Bristol,Avon): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in - on line 64 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in -:65 Stack trace: #0 -(65): SimpleXMLElement->__construct('') #1 -(89): getWeather('http://www.goog...') #2 {main} thrown in - on line 65 ( line 64 is this one: $xml_str = file_get_contents($geourl,0); ) This is taking me way longer than I though it would
  4. How would I successfully do this? Like I said, I'm new here! I really do appreciate the help.
  5. Hmmm, yes I think you're right. When I use this code it works fine: $geourl = "http://www.google.com/ig/api?weather=,,,bristol,avon"; Yet, when I attempt to use the variables like before: $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; It doesn't work! What is different? Any ideas? Thanks again.
  6. Thanks, Thorpe. It actully does appear to be the line below that is causing the error ( $xml = new SimplexmlElement($xml_str); ) Here's the full code. <?php $city = "<script language='javascript'>document.write(geoip_city());</script>"; $county = "<script language='javascript'>document.write(geoip_region_name());</script>"; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; function getWeather() { $xml_str = file_get_contents($geourl,0); $xml = new SimplexmlElement($xml_str); $count = 0; echo '<div id="weather">'; foreach($xml->weather as $item) { foreach($item->current_conditions as $new) { echo $new->condition['data']; echo '<br/>'; echo $new->temp_c['data']; echo '°C'; echo '<br/>'; echo $new->wind_condition['data']; } } echo '</div>'; } getWeather(); ?>
  7. Hi, I'm still pretty new to PHP and am currently working on a personal project to help learn. I am trying to detect a user's location, store their city and region and then build a URL containing these for later use. <?php $city = "<script language='javascript'>document.write(geoip_city());</script>"; $county = "<script language='javascript'>document.write(geoip_region_name());</script>"; $geourl = "http://www.google.com/ig/api?weather=,,," . $city . "," . $county; ?> If I echo $geourl then it displays just fine but when I attempt to use it, it throws an error 'String could not be parsed as XML' . $xml_str = file_get_contents($geourl,0); Any help appreciated, I just can't get my head around it! Fez
  8. Yes! It's now working. Thankyou, Addict.
  9. Thank you for your help but it still doesn't work! Addict, I inserted your code and it still doesn't seem to work. This is the error: Parse error: syntax error, unexpected T_ELSE in XXXXXX on line 180 (line 180 is the line with just 'else') Herghost, this doesn't seem to work either. wildteen88, I did miss this on the code snippet I posted but this doen't seem to be the problem. Line 182 on the original code snippet was also the line with just 'else' on it. Thanks again, any more help appreciated!
  10. Hi, I'm trying to display a user review system allowing user's to vote. This works fine, but I'm trying to user php to only display the rating system if the user is logged in and display alternate text if they are not. I am getting the following error: Parse error: syntax error, unexpected T_ELSE in XXXXXX on line 182 Here's the code: <?php if ($_SESSION['username']){ $query = mysql_query("SELECT * FROM locations WHERE name = '$location'"); while($row = mysql_fetch_array($query)) { $rating = (int)$row[rating] ?> <div class="floatleft"> <div id="rating_<?php echo $row[id]; ?>"> <span class="star_1"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span> <span class="star_2"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span> <span class="star_3"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span> <span class="star_4"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span> <span class="star_5"><img src="fivestars/star_blank.png" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span> </div> </div> <div class="star_rating"> (Rated <strong><?php echo $rating; ?></strong> Stars) </div> <div class="clearleft"> </div> } } <?php else { echo "Log in to review"; } ?> Thanks in advance for any help. I'm sure it's something trivial but I can't see it!
  11. Hello, I'm new! I am trying to populate a list of locations based on ratings. I can populate the list just fine but it's displaying every record in the table. Is there a way of only looping 4 times so as to just display the top 4 records? Here's the code: $result = mysql_query("SELECT * FROM locations ORDER BY rating DESC"); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br>; } Thankyou in advance for any help
×
×
  • 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.