Jump to content

jbw

New Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by jbw

  1. Hi all, With the working code below I;m trying to setup a results section that would output a soccer teams results eg.Everton have won 12, drawn 4, and lost 5 games to date. The team position option works fine but I;m not sure how to integrate the additional function within the code for the results section? Thanks for the help. Regards. <html> <head> <style> .red {color: red} </style> <title>Table</title> </head> <body> <?php if ($_SERVER["REQUEST_METHOD"] == "POST" ){ $tablesPage = "http://www.bbc.com/sport/football/tables"; $resultsPage = "http://www.bbc.com/sport/football/results"; // I need this to output results data as in the tables option if(!empty($_POST["team"])){ $teamData= getTeamData($_POST["team"] , $tablesPage); if(!empty($_POST["data"]) && $_POST["data"] == "position"){ echo getPosition($teamData); } } } function getPosition($teamData){ return "Team ". $teamData["team"] ." are currently number " . $teamData["position"] . " in the league "; } function getTeamData($team, $tablesPage){ $html = new DOMDocument(); @$html->loadHtmlFile($tablesPage); @$xpath = new DOMXPath($html); / $items = $xpath->query('//td/a[text()=' . $team . ']/../..'); $values[] = array(); foreach($items as $node){ foreach($node->childNodes as $child) { if($child->nodeType == 1) array_push($values, $child->nodeValue); } } $values[2] = substr($values[2], -1); $values = array_slice( $values, 2, count($values)-4); $keys = array("position", "team", "played", "won", "drew", "lost", "for", "against", "difference", "points"); return array_combine($keys, $values); } ?> <br> Select a team and a data item about that team <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <select name="team"> <option value=""></option> <option value="Everton">Everton</option> <option value="Chelsea">Chelsea</option> <option value="Southampton">Southampton</option> <option value="Liverpool">Liverpool</option> <option value="Arsenal">Arsenal</option> </select> <select name="data"> <option value="position">position</option> <option value="results">results</option> <select> <input type="submit" value="Get Data"></input> </select> </form> </body> </html> Test.php
  2. jbw

    Nested Loops

    Perfect!!!!! thanks. I was wondering if you could help again in relation to the same output but this time modify the code to make the numbers smaller from 1 and biggest at 5. >>> 1 12 123 1234 12345 Regards.
  3. jbw

    Nested Loops

    I just got it working!! <?php for ($row = 1; $row <= 5; $row++) { for ($col = 1; $col <= $row; $col++) { echo "$col"; } echo "<br>"; } ?> Cheers.
  4. jbw

    Nested Loops

    <?php for ($row = 1; $row <= 5; $row++) { for ($col = 1; $col <= $row; $col++) { echo '*'; } echo "<br>"; } ?>
  5. jbw

    Nested Loops

    Hi , No limits, just to produce the outcome of >>> 1 12 123 1234 12345 here is a close working example>> for ($row = 1; $row <= 5; $row++) { for ($col = 1; $col <= $row; $col++) { echo '*'; } echo "\n"; } Thanks, Regards.
  6. Hi, I hope you can help with the issue below. I'm trying to create a nested loop to output numbers as listed below but I can't get it to work correctly? ie. 1 12 123 1234 12345 $count =1; for ($row = 0; $row <=4; $row++) { for ($num = 0; $num <=$row; $count++){ echo ""; } echo "<br>"; } Regards, James.
  7. Hi all, I hope somebody can shed some light on a PHP program I'm trying to run related to loops. I have created a 1 - 10 loop as >> for ($x=0; $x<=10; $x++) { echo " $x <br>"; } but now I want to modify it so that each number that is divisible by two is bold? ie. 1 2 = bold 3 4 = bold 5 6= bold 7 8 = bold 9 10 = bold Regards, James.
×
×
  • 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.