flemingmike
-
Posts
472 -
Joined
-
Last visited
Posts posted by flemingmike
-
-
hi all,
quick question... if i have 5 pictures pic1.jpg, pic2.jpg, pic3.jpg, pic4.jpg and pic5.jpg and im viewing pic3.jpg, is there an easy way to make a left and right button to scroll through the pictures by adding or extracting a number?
thx.
-
thanks. it worked
-
hi, where would i make it so each result is on its own line, left aligned?
<?php $RSS_Content = array(); function RSS_Tags($item, $type) { $y = array(); $tnl = $item->getElementsByTagName("title"); $tnl = $tnl->item(0); $title = $tnl->firstChild->textContent; $tnl = $item->getElementsByTagName("link"); $tnl = $tnl->item(0); $link = $tnl->firstChild->textContent; $tnl = $item->getElementsByTagName("pubDate"); $tnl = $tnl->item(0); $date = $tnl->firstChild->textContent; $tnl = $item->getElementsByTagName("description"); $tnl = $tnl->item(0); $description = $tnl->firstChild->textContent; $y["title"] = $title; $y["link"] = $link; $y["date"] = $date; $y["description"] = $description; $y["type"] = $type; return $y; } function RSS_Channel($channel) { global $RSS_Content; $items = $channel->getElementsByTagName("item"); // Processing channel $y = RSS_Tags($channel, 0); // get description of channel, type 0 array_push($RSS_Content, $y); // Processing articles foreach($items as $item) { $y = RSS_Tags($item, 1); // get description of article, type 1 array_push($RSS_Content, $y); } } function RSS_Retrieve($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { RSS_Channel($channel); } } function RSS_RetrieveLinks($url) { global $RSS_Content; $doc = new DOMDocument(); $doc->load($url); $channels = $doc->getElementsByTagName("channel"); $RSS_Content = array(); foreach($channels as $channel) { $items = $channel->getElementsByTagName("item"); foreach($items as $item) { $y = RSS_Tags($item, 1); // get description of article, type 1 array_push($RSS_Content, $y); } } } function RSS_Links($url, $size = 15) { global $RSS_Content; $page = "<ul>"; RSS_RetrieveLinks($url); if($size > 0) $recents = array_slice($RSS_Content, 0, $size + 1); foreach($recents as $article) { $type = $article["type"]; if($type == 0) continue; $title = $article["title"]; $link = $article["link"]; $page .= "<li><a href=\"$link\">$title</a></li>\n"; } $page .="</ul>\n"; return $page; } function RSS_Display($url, $size = 15, $site = 0, $withdate = 0) { global $RSS_Content; $opened = false; $page = ""; $site = (intval($site) == 0) ? 1 : 0; RSS_Retrieve($url); if($size > 0) $recents = array_slice($RSS_Content, $site, $size + 1 - $site); foreach($recents as $article) { $type = $article["type"]; if($type == 0) { if($opened == true) { $page .="</ul>\n"; $opened = false; } $page .="<b>"; } else { if($opened == false) { $page .= "<ul>\n"; $opened = true; } } $title = $article["title"]; $link = $article["link"]; $page .= "<li><a href=\"$link\">$title</a>"; if($withdate) { $date = $article["date"]; $page .=' <span class="rssdate">'.$date.'</span>'; } $description = $article["description"]; if($description != false) { $page .= "<br><span class='rssdesc'>$description</span>"; } $page .= "</li>\n"; if($type==0) { $page .="</b><br />"; } } if($opened == true) { $page .="</ul>\n"; } return $page."\n"; } ?>
it looks very wierd right now. http://durhamit.ca/kpc/mlbnews.php
-
no database. sorry, my mistake. instert into table like:
echo "<table border=4 cellpadding=4 cellspacing=0 align=center width=800><tr><td><b>MLB News</b></td></tr>";
echo "</table>";
-
sorry for the newbie questions, i try to figure things out for about 2 hours before i ask questions.
right now im having a problem getting my data into a table. i can get it to show on the screen. here is the code.
$url1 = "http://sports.espn.go.com/espn/rss/mlb/news"; echo RSS_Display($url1, 8, false, true);
thanks for the help!
-
i tried this, but i must me doing it wrong or in wront place...
if ( $sport == 'URL' && preg_match("/s_url\d+/", $value) ) { $results[<a href="$sport"></a>][] = $foo[2][$key]; }
-
can i do that when its constantly changing?
-
hi all,
i cannot seem to figure out how to make the url active when i parse it from a string. any ideas?
<?php //this array contains sports and their URLs $sports = array( "NHL" => "http://sports.espn.go.com/nhl/bottomline/scores", "URL" => "http://sports.espn.go.com/nhl/bottomline/scores"); $results = array(); foreach ( $sports as $sport => $url ) { //get the page pointed to by $url $page = file_get_contents($url); //grab all variables out of the page preg_match_all("/&([^=]+)=([^&]+)/", urldecode($page), $foo); //loop through all the variables on the page foreach ( $foo[1] as $key => $value ) { //debug output, you can delete this next line //echo "{$value} = {$foo[2][$key]}\t<br />\n"; //this chain of IF/elseif statements is used to determine which pattern to use //to strip out the correct data, since each sport seems to have its own format //for the variables you'd "want" if ( $sport == 'URL' && preg_match("/s_url\d+/", $value) ) { $results[$sport][] = $foo[2][$key]; } elseif ( $sport == "NHL" && preg_match("/s_left\d+/", $value) ) { $results[$sport][] = $foo[2][$key]; } } } //calculate the sport with the most number of rows $limit = 0; foreach ( $results as $countMe ) { $limit = max($limit, count($countMe)); } //spit out the table with the right headers echo '<img src="nhl.jpg">'; echo "<table border=1 cellpadding=2><tr><th>" . implode("</th><th>", array_keys($sports)) . "</th></tr>"; //loop until you reach the max number of rows, printing out all the table rows you want for ( $p = 0; $p < $limit; $p++ ) { echo "<tr align=center>"; foreach ( array_keys($sports) as $sport ) { echo "<td>{$results[$sport][$p]}</td>"; } echo "</tr>"; } //kill the table echo "</table>";
-
Thank you all very much!!
-
thanks for that, page cannot be shown. i think i might have an extra } in there.
<?php class weather { public static $response; public static $location; public static $current; public static $nextdays; public static $error = false; public function weather() { $this->location = 'Pickering, ON'; } public function get() { if (empty($this->location)) { $this->error = true; return false; } $requestAddress = "http://www.google.com/ig/api?weather=".trim(urlencode($this->location))."&hl=en"; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); if (!$xml->weather->problem_cause) { $this->response = $xml->weather; $this->parse(); }else{ $this->error = true; } } public function parse() { foreach($this->response as $item) { $this->current = $item->current_conditions; foreach($item->forecast_conditions as $new) { $this->nextdays[] = $new; } } } public function display() { echo '<table border=1 cellpadding=2 align=center>'; echo '<tr align=center>'; foreach($this->nextdays as $new) { echo '<td>'; echo '<div class="weatherIcon">'; echo '<h2>'.$new->day_of_week['data'].'</h2>'; echo '<img src="http://www.durhamit.ca/test/' .$new->icon['data'] . '"/><br/>'; echo '<br />Min: '.$this->convert($new->low['data']).' &#38;#8451;'; echo '<br />Max: '.$this->convert($new->high['data']).' &#38;#8451;'; echo '<br />'.$new->condition['data'].' '; echo '</div>'; echo '</td>'; } echo '</tr>'; echo '</table>';} } } public function convert($value, $unit = "C"){ switch($unit){ case "C": return number_format(($value - 32)/1.; }; } }
-
ok, so i have everything in a table now, but the table is vertical. how can i make it horizontal?
<?php class weather { public static $response; public static $location; public static $current; public static $nextdays; public static $error = false; public function weather() { $this->location = 'Pickering, ON'; } public function get() { if (empty($this->location)) { $this->error = true; return false; } $requestAddress = "http://www.google.com/ig/api?weather=".trim(urlencode($this->location))."&hl=en"; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); if (!$xml->weather->problem_cause) { $this->response = $xml->weather; $this->parse(); }else{ $this->error = true; } } public function parse() { foreach($this->response as $item) { $this->current = $item->current_conditions; foreach($item->forecast_conditions as $new) { $this->nextdays[] = $new; } } } public function display() { foreach($this->nextdays as $new) { echo '<table border=1 cellpadding=2 align=center>'; echo '<tr align=center>'; echo '<td>'; echo '<div class="weatherIcon">'; echo '<h2>'.$new->day_of_week['data'].'</h2>'; echo '<img src="http://www.durhamit.ca/test/' .$new->icon['data'] . '"/><br/>'; echo '<br />Min: '.$this->convert($new->low['data']).' ℃'; echo '<br />Max: '.$this->convert($new->high['data']).' ℃'; echo '<br />'.$new->condition['data'] . ' '; echo '</td> '; echo '</div>'; } } public function convert($value, $unit = "C"){ switch($unit){ case "C": return number_format(($value - 32)/1.; echo '</tr>'; echo '</table>'; }; } }
-
that sepparated all the info for the current day. that part is fine how i had it. im trying to get fri, sat, sun and mon to be side by side.
the part that says
$weather->display();}
i believe this is just running a loop on the data??
i think this is where i am failing
-
i think im getting closer.
index.php:
<?php include("style.php"); require_once('pickering_api.php'); $weather = new weather(); if (!empty($_GET['loc'])) { $weather->location = $_GET['loc']; } $weather->get(); if($weather->error){ die('We couldn\'t find your location.'); } else{ echo ' <div id="currentWeather"> <table border=1 cellpadding=2 align=center> <tr align=center> <td> <h2>Right Now In '.ucwords($weather->location).'</h2> <br /><img src="http://www.durhamit.ca/test/' .$weather->current->icon['data'] . '"/> <br />'.$weather->current->temp_c['data'].' ℃ <br />'.$weather->current->condition['data'].' <br />'.$weather->current->humidity['data'].' <br />'.$weather->current->wind_condition['data'].' </td> <td> </td> <td> </td> </tr> </table> </div>'; // display more days info // print_r($weather->nextdays); $weather->display(); }
pickering_api.php:
<?php class weather { public static $response; public static $location; public static $current; public static $nextdays; public static $error = false; public function weather() { $this->location = 'Pickering'; } public function get() { if (empty($this->location)) { $this->error = true; return false; } $requestAddress = "http://www.google.com/ig/api?weather=".trim(urlencode($this->location))."&hl=en"; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); if (!$xml->weather->problem_cause) { $this->response = $xml->weather; $this->parse(); }else{ $this->error = true; } } public function parse() { foreach($this->response as $item) { $this->current = $item->current_conditions; foreach($item->forecast_conditions as $new) { $this->nextdays[] = $new; } } } public function display() { foreach($this->nextdays as $new) { echo '<div class="weatherIcon">'; echo '<h2>'.$new->day_of_week['data'].'</h2>'; echo '<img src="http://www.durhamit.ca/test/' .$new->icon['data'] . '"/><br/>'; echo '<br />Min: '.$this->convert($new->low['data']).' ℃'; echo '<br />Max: '.$this->convert($new->high['data']).' ℃'; echo '<br />'.$new->condition['data'] . ' '; echo '</div>'; } } public function convert($value, $unit = "C"){ switch($unit){ case "C": return number_format(($value - 32)/1.; break; case "F": return round($value * 1.8 + 32); break; default: return $value; break; }; } }
am i getting closer?
-
im stuck here.
<?php include("style.php"); require_once('pickering_api.php'); $weather = new weather(); if (!empty($_GET['loc'])) { $weather->location = $_GET['loc']; } $weather->get(); if($weather->error){ die('We couldn\'t find your location.'); } else{ echo ' <div id="currentWeather"> <table border=1 cellpadding=2 align=center> <tr align=center> <td> <h2>Right Now In '.ucwords($weather->location).'</h2> <br /><img src="http://www.durhamit.ca/test/' .$weather->current->icon['data'] . '"/> <br />'.$weather->current->temp_c['data'].' ℃ <br />'.$weather->current->condition['data'].' <br />'.$weather->current->humidity['data'].' <br />'.$weather->current->wind_condition['data'].' </td> <td> <h2>Right Now In '.ucwords($weather->location).'</h2> <br /><img src="http://www.durhamit.ca/test/' .$weather->current->icon['data'] . '"/> <br />'.$weather->current->temp_c['data'].' ℃ <br />'.$weather->current->condition['data'].' <br />'.$weather->current->humidity['data'].' <br />'.$weather->current->wind_condition['data'].' </td> <td>$weather->display(); } </td> </tr> </table> </div> '; // display more days info // print_r($weather->nextdays); $weather->display(); }
-
i keep trying different ways, but i feel like there is an error in how im displaying the array. it keeps going vertical, even in a table.
-
would i do that in the api? im kinda new
-
hi all,
i have 2 sets of code. it currently displays weather vertically, i cant for the life of me figure out how to get it into a horizontal table. any help is appreciated.
http://www.durhamit.ca/test/example.php
example.php
<?php require_once('google_weather_api.php'); $weather = new weather(); if (!empty($_GET['loc'])) { $weather->location = $_GET['loc']; } $weather->get(); if($weather->error){ die('We couldn\'t find your location.'); } else{ echo ' <div id="currentWeather"> <h1>Now in '.ucwords($weather->location).': '.$weather->current->temp_c['data'].' ℃</h1> <img src="http://www.google.com/' .$weather->current->icon['data'] . '"/> <p>'.$weather->current->condition['data'].'</p> <p>'.$weather->current->humidity['data'].'</p> <p>'.$weather->current->wind_condition['data'].'</p> </div> '; // display more days info // print_r($weather->nextdays); $weather->display(); }
google_weather_api.php
<?php class weather { public static $response; public static $location; public static $current; public static $nextdays; public static $error = false; public function weather() { $this->location = 'Pickering, ON'; } public function get() { if (empty($this->location)) { $this->error = true; return false; } $requestAddress = "http://www.google.com/ig/api?weather=".trim(urlencode($this->location))."&hl=en"; $xml_str = file_get_contents($requestAddress,0); $xml = new SimplexmlElement($xml_str); if (!$xml->weather->problem_cause) { $this->response = $xml->weather; $this->parse(); }else{ $this->error = true; } } public function parse() { foreach($this->response as $item) { $this->current = $item->current_conditions; foreach($item->forecast_conditions as $new) { $this->nextdays[] = $new; } } } public function display() { foreach($this->nextdays as $new) { echo '<div class="weatherIcon">'; echo '<h2>'.$new->day_of_week['data'].'</h2>'; echo '<img src="http://www.durhamit.ca/test/' .$new->icon['data'] . '"/><br/>'; echo '<br />Min: '.$this->convert($new->low['data']).' ℃'; echo '<br />Max: '.$this->convert($new->high['data']).' ℃'; echo '</div>'; } } public function convert($value, $unit = "C"){ switch($unit){ case "C": return number_format(($value - 32)/1.; break; case "F": return round($value * 1.8 + 32); break; default: return $value; break; }; } }
-
hi, anybody have a php page that displays a couple of days forcast? ive been trying to make one for about 4 days and i get nowhere. i dont ever care if it is just yahoo weather. preferably horizontal layout.
thanks.
mike
-
i know how to make links, but the url column is being parsed from a url string and then placed in the table. im not sure how to make it a link rather than just text.
-
2 questions... in my code, where would i put my style, ie. background colors, etc.
second question, how would i make the second column (url) an actual link?
here is my code:
<?php //this array contains sports and their URLs $sports = array( "MLB" => "http://sports.espn.go.com/mlb/bottomline/scores", "URL" => "http://sports.espn.go.com/mlb/bottomline/scores"); $results = array(); foreach ( $sports as $sport => $url ) { //get the page pointed to by $url $page = file_get_contents($url); //grab all variables out of the page preg_match_all("/&([^=]+)=([^&]+)/", urldecode($page), $foo); //loop through all the variables on the page foreach ( $foo[1] as $key => $value ) { //debug output, you can delete this next line //echo "{$value} = {$foo[2][$key]}\t<br />\n"; //this chain of IF/elseif statements is used to determine which pattern to use //to strip out the correct data, since each sport seems to have its own format //for the variables you'd "want" if ( $sport == 'URL' && preg_match("/s_url\d+/", $value) ) { $results[$sport][] = $foo[2][$key]; } elseif ( $sport == "MLB" && preg_match("/s_left\d+/", $value) ) { $results[$sport][] = $foo[2][$key]; } } } //calculate the sport with the most number of rows $limit = 0; foreach ( $results as $countMe ) { $limit = max($limit, count($countMe)); } //spit out the table with the right headers echo '<img src="mlb.gif">'; echo "<table border=1 cellpadding=2><tr><th>" . implode("</th><th>", array_keys($sports)) . "</th></tr>"; //loop until you reach the max number of rows, printing out all the table rows you want for ( $p = 0; $p < $limit; $p++ ) { echo "<tr align=center>"; foreach ( array_keys($sports) as $sport ) { echo "<td>{$results[$sport][$p]}</td>"; } echo "</tr>"; } //kill the table echo "</table>";
thanks,
mike
-
hi, im hoping i can cleanup my results and then make a new page that can place the results in a nice table. here is my code:
<?php $content1 = file_get_contents('http://sports.espn.go.com/mlb/bottomline/scores'); parse_str($content1,$vars); echo '<pre>'.print_r($vars, true).'</pre>'; ?>
page can be seen at http://durhamit.ca/test/test.php
-
how about taking this data and dividing it into each game and outputting as rss page? is that easy?
-
im slowly getting it now. is it easy to put groups into a table? or should i just be paying someone to do this for me?
-
i feel even dumber now... i made a new file called test and i put this in it:
<?php $content = file_get_contents('http://sports.espn.go.com/mlb/bottomline/scores'); parse_str($content,$vars); ?>
i get nothing when i try open that page now. did i screw it up?
should this work, or am i stupid?
in PHP Coding Help
Posted
hello,
i was going through a tutorial on how to display xml data on a website. here is my xml output from my music player:
here is the code that i thought would display the artists name:
should this work?