Jump to content

pake

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

pake's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hehe, found an easier way to do this - though it required a small change in my xml too. <?php // load xml for the match details $xml = 'matches.xml'; echo "xml loaded: $xml <br /><br />"; //debug $dom = new DOMDocument; $dom->load($xml); if (!$dom) { echo 'Error while parsing the XML ($xml)'; exit; } // get the data from xml to the variable $XMLdata $XMLdata = simplexml_import_dom($dom); foreach($XMLdata->matchdetails as $matchdetails) { $link = $matchdetails->link; $date = $matchdetails->date; $time = $matchdetails->time; $place = $matchdetails->place; $match = $matchdetails->match; list($home,$away) = explode ( ' - ' , $match ); $score = $matchdetails->score; echo '<tr>'; echo '<td width="20%" align="right"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$date.'</a></td>'; echo '<td width="8%" align="center"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$time.'</td>'; echo '<td width="20%" align="left"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$place.'</td>'; echo '<td width="20%" align="left"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$home.'</td>'; echo '<td width="20%" align="left"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$away.'</td>'; echo '<td align="center"><a href="#'.$link.'" onclick="loadContent(\'#content\', \'ottelut_raportti.php?id=\''.$link.'\')">'.$score.'</td>'; echo '</tr>'; } ?> </table>
  2. I'm importing data from xml to my php-page. Since I'm a php-n00b I don't know how to make this easier (more dynamic) and I'm here to ask help (in order to learn). It's easier to explain what I want by showing my script so here's my code atm: <?php // load xml $xml = 'matches.xml'; echo "xml loaded: $xml <br /><br />"; //debug $dom = new DOMDocument; $dom->load($xml); if (!$dom) { echo 'Error while parsing the XML ($xml)'; exit; } // get the data from xml to the variable $XMLdata $XMLdata = simplexml_import_dom($dom); //echo $XMLdata->name[0]; //debug $link1 = $XMLdata->link[0]; $day1 = $XMLdata->day[0]; $time1 = $XMLdata->time[0]; $place1 = $XMLdata->place[0]; $match1 = $XMLdata->match[0]; list($home1,$away1) = explode ( ' - ' , $match1 ) ; $score1 = $XMLdata->score[0]; $link2 = $XMLdata->link[1]; $day2 = $XMLdata->day[1]; $time2 = $XMLdata->time[1]; $place2 = $XMLdata->place[1]; $match2 = $XMLdata->match[1]; list($home2,$away2) = explode ( ' - ' , $match2 ) ; $score2 = $XMLdata->score[1]; $link3 = $XMLdata->link[2]; $day3 = $XMLdata->day[2]; $time3 = $XMLdata->time[2]; $place3 = $XMLdata->place[2]; $match3 = $XMLdata->match[2]; list($home3,$away3) = explode ( ' - ' , $match3 ) ; $score3 = $XMLdata->score[2]; $link4 = $XMLdata->link[3]; $day4 = $XMLdata->day[3]; $time4 = $XMLdata->time[3]; $place4 = $XMLdata->place[3]; $match4 = $XMLdata->match[3]; list($home4,$away4) = explode ( ' - ' , $match4 ) ; $score4 = $XMLdata->score[3]; // ...continues // add rows to the table for ($i=1; $i<=25; $i++) { $link = "link".$i; $day = "day".$i; $time = "time".$i; $place = "place".$i; $home = "home".$i; $away = "away".$i; $score = "score".$i; echo '<tr>'; echo '<td width="20%" align="right"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$day.'</a></td>'; echo '<td width="8%" align="center"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$time.'</td>'; echo '<td width="20%" align="left"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$place.'</td>'; echo '<td width="20%" align="left"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$home.'</td>'; echo '<td width="20%" align="left"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$away.'</td>'; echo '<td align="center"><a href="#'.$$link.'" onclick="loadContent(\'#content\', \'matcht_raportti.php?id=\''.$$link.'\')">'.$$score.'</td>'; echo '</tr>'; } ?> As you can see it's not wise to fetch the xml nodes one by one manually. How could I get all the data from the xml in one loop? So how should this part below be? $linkki1 = $XMLdata->linkki[0]; $paiva1 = $XMLdata->paiva[0]; $kello1 = $XMLdata->kello[0]; $paikka1 = $XMLdata->paikka[0]; $ottelu1 = $XMLdata->ottelu[0]; list($koti1,$vieras1) = explode ( ' - ' , $ottelu1 ) ; $tulos1 = $XMLdata->tulos[0]; If there's anything else you would change I'm all ears... I know the for-loop isn't too classy either but at least it works. I'm open for suggestions regarding to that too.
  3. I found a better(?) way to get what I want. Thank God for jquery In team.php's head-tag there's: <script type="text/javascript" src="includes/jquery-1.6.1.min.js"></script> <script type="text/javascript" language="javascript"> function loadContent(elementSelector, sourceURL) { $(""+elementSelector+"").load(""+sourceURL+""); } </script> and in the player selection menu there's: <a href="#" onclick="loadContent('#content', 'team_players.php?id=player1.xml')"> where the xml filename varies. The whole content of the page is in the team_players.php where I'm supposed to import the xml's data into tables etc. After some initial testing I'm pretty sure I will be asking for help in a few days on the "import data from xml to tables"-issue... I'll try to figure it out myself first and if I can't manage --> I'll be back. BTW. Which is better (and why?) 1) <a href="#" onclick="loadContent('#content', 'team_players.php?id=player1.xml')"> or 2) <a href="javascript:loadContent('#content', 'team_players.php?id=player1.xml');"> ?
  4. Thanks. I tried to modify that example to suit my needs but didn't succeed. Here's my problem: I have the javascript (makeRequest-function etc) in the <head>-tag of the php-file. I created a variable "testi" which contains the xml's content. However, I can't use that variable later in the php-file (in the <body>-tag), like this: <body> <div id="content"> . . <div id="playerPicture"> <script type="text/javascript"> document.write(testi); </script> </div> . . </div> . . </body> How should I fix this problem? Should I put that <script>-tag inside the <div id="content">-tag or is there a way to get that variable work outside the <head>-tag?
  5. Hi guys. Here's my story. I've done a few html and flash sites before but now I wanted to learn php and AJAX too. I don't consider myself as a real programmer (even though I use perl daily at work). To be honest, I'm more of a "copy-paste-edit"-kind of guy who has way too little time. I'd like to get help in order to get things going on my quest to learn php & AJAX... I'm creating a new website for our floorball team and I'd like to use XMLs to import player data to each players own page. (I chose XML since it would be easier to update the data/statistics). Instead of making a php-file/page (+an xml-file) for each individual player, I'd like to have only one php-page that gets all the data it needs from xml-files (player1.xml, player2.xml etc.) without reloading the whole page. In my vision there's a list of players (as a menu) and when you click on a name a script loads the chosen player's xml and passes on the data (picture+statistics) to the content section of the page. I guess I should use AJAX for that, am I right? I've tried googleing but haven't really found a usable tutorial / example yet. Anyone wanna help me out here? I was thinking of using XMLs like this: <?xml version="1.0" encoding="utf-8"?> <player name="Eric Example"> <picture url="images/example.jpg"> <stats value="2009-2010"> <games>17</games> <goals>27</goals> <assists>20</assists> <points>47</points> <penalties>2</penalties> </stats> <stats value="2010-2011"> <games>10</games> <goals>15</goals> <assists>15</assists> <points>30</points> <penalties>5</penalties> </stats> </player> I would like to get the stats from the xml to be shown in a table form (see the attachment) so that it automatically adds the necessary rows when the data grows. Am I way over my head here and if so, is anyone willing to help me out? Or should I do things in some other (better) way? [attachment deleted by admin]
×
×
  • 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.