Jump to content

DIM3NSION

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by DIM3NSION

  1. I want to loop through a MySQL table, and perform a calculation based on the current row the loop is on and the previous loop. Say my table has 2 columns - Film_id and FilmRelease, how would I loop through and echo out a calculation of the current FilmRelease and the previous row's column value? Thanks guys I have got to this stage, but for some reason it's not printing out anything <?php mysql_connect("localhost", "****", "*****") or die(mysql_error()); mysql_select_db("*****") or die(mysql_error()); $sql = mysql_query("SELECT FilmRelease FROM Films_Info") or die(mysql_error()); $last_value = null; while ($row = mysql_fetch_assoc($sql)) { if (!is_null($last_value)) { print date_diff($row['FilmRelease'], $last_value) . "<BR>"; } $last_value = $row['FilmRelease']; }
  2. Hi guys. I have been using the wikipedia API to retrieve information about a topic. Ive managed to get a response and retrieve the first section of the topic (in this case football) Using this method - http://en.wikipedia.org/w/api.php?action=parse&page='.$search.'&redirects=1&format=json&prop=text&section=0'); However the first section that is retrieved includes the pictures and i just want to main text from the introduction. The code that is sent back from wiki is this - Array ( [parse] => Array ( [text] => Array ( [*] => <div class="dablink">This article is about sports known as football. For the ball used in these sports, see <a href="/wiki/Football_(ball)">Football (ball)</a>.</div> <div class="thumb tright"> <div class="thumbinner" style="width:227px;"><a href="/wiki/File:Football4.png" class="image"><img alt="" src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Football4.png/225px-Football4.png" width="225" height="274" class="thumbimage" /></a> <div class="thumbcaption"> <div class="magnify"><a href="/wiki/File:Football4.png" class="internal" title="Enlarge"><img src="http://bits.wikimedia.org/skins-1.17/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div> Some of the many different games known as football. From top left to bottom right: <a href="/wiki/Association_football">Association football</a> or soccer, <a href="/wiki/Australian_rules_football">Australian rules football</a>, <a href="/wiki/International_rules_football">International rules football</a>, <a href="/wiki/Rugby_Union" class="mw-redirect" title="Rugby Union">Rugby Union</a>, <a href="/wiki/Rugby_League" class="mw-redirect" title="Rugby League">Rugby League</a>, and <a href="/wiki/American_Football" class="mw-redirect" title="American Football">American Football</a>.</div> </div> </div> <p>The game of <b>football</b> is any of several similar <a href="/wiki/Team_sport" title="Team sport">team sports</a>, of similar origins which involve advancing a ball into a goal area in an attempt to score. Many of these involve <a href="/wiki/Kick_(football)" title="Kick (football)">kicking</a> a ball with the foot to score a <a href="/wiki/Goal_(sport)" title="Goal (sport)">goal</a>, though not all codes of football using kicking as a primary means of advancing the ball or scoring. The most popular of these sports worldwide is <a href="/wiki/Association_football">association football</a>, more commonly known as just "football" or "soccer". Unqualified, the word <i><a href="/wiki/Football_(word)" title="Football (word)">football</a></i> applies to whichever form of football is the most popular in the regional context in which the word appears, including <a href="/wiki/American_football">American football</a>, <a href="/wiki/Australian_rules_football">Australian rules football</a>, <a href="/wiki/Canadian_football">Canadian football</a>, <a href="/wiki/Gaelic_football">Gaelic football</a>, <a href="/wiki/Rugby_league">rugby league</a>, <a href="/wiki/Rugby_union">rugby union</a> and other related games. These variations are known as "codes".</p> I want the code that resides in the <p> tags. How would i go about parsing this and removing the rest. ive tried to get to work simple html dom parser but with no luck. Any help would be greatly appreciated Thanks, DIM3NSION
  3. Perfect, been stumped for a good week on this. Thanks alot
  4. Would i have to do a foreach loop on that? foreach ($xmlmusic as $xm) { $attrs = $xm->attributes(); if($attrs['type'] == "release") echo $xm->summary."\n"; } Ive tried this but with no luck. Is there anything wrong with that code? Thanks for your help, DIM3NSION
  5. I have a simpleXMLelement and the element objects in the array have the attribute [type]. This distinguishes them from each other. How would i go about parsing the objects that just have the attribute type set to [type] => release and displaying the summary section of that object. below is an simpleXMLelement object code as an example [6] => SimpleXMLElement Object ( [@attributes] => Array ( [num] => 7 [type] => master ) [title] => DJ Tiësto - Sparkles [uri] => http://www.discogs.com/DJ-Tiësto-Sparkles/master/4001 [summary] => DJ Tiësto Sparkles Electronic Trance 1999 Sparkles (Airscape Remix) Sparkles (Original) Sparkles ) and this is the PHP that creates the element - $xmlmusic = new SimpleXMLElement($result); Thanks guys. DIM3NSION
  6. Hi Guys. I'm struggling to find a way to access parts of an XML document through PHP Ive managed to use cURL to get a response from an api that lists music artists album releases - I have got the response loaded into a simpleXMLelement. printing out the code it returns an array that looks like this - [2] => SimpleXMLElement Object ( [@attributes] => Array ( [num] => 3 [type] => artist ) [title] => DJ Tiësto [uri] => http://www.discogs.com/artist/DJ+Ti%C3%ABsto [summary] => DJ Tiësto Tijs Michiel Verwest Dutch trance DJ & producer (there are multiple entries in the array with different content types) What i'm trying to achieve is to parse this xml code so that all the array items that have the attribute type set to artist then display the summary code for it. This is the full PHP code i have but it doesn't return anything. <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.discogs.com/search?type=all&" . "q=DJ+Tiësto&" . "f=xml&" . "api_key=<APIKEY>"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_ENCODING, "gzip"); $result = curl_exec($curl); curl_close($curl); $xmlmusic = new SimpleXMLElement($result,NULL,true); foreach ($xmlmusic as $xm) { $attrs = $xm->attributes(); if($attrs["type"] == "title") echo $xm->summary."\n"; } ?> Am i going in the right direction?
×
×
  • 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.