Jump to content

Search the Community

Showing results for tags 'multiple attribute'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hello , i have had made a number of changes to the below program but am really stumped on my last task- i need a multiple attribute to pull multiple 'teams' data (points,goal difference etc) with php form. i can get single teams to work but not multiple. see screen attached and heres my code below. <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"; if(!empty($_POST["team"])){ $teamData= getTeamData($_POST["team"] , $tablesPage); //get associative array of team data if(!empty($_POST["data"]) && $_POST["data"] == "results"){ echo getResults($teamData); } else if(!empty($_POST["data"]) && $_POST["data"] == "position"){ echo getPosition($teamData); } else if(!empty($_POST["data"]) && $_POST["data"] == "two points for a win"){ echo getPoints($teamData); } else if(!empty($_POST["data"]) && $_POST["data"] == "goal difference"){ echo getDifference($teamData); } } } function getPosition($teamData){ /*This function takes an array of team data and returns a string containing the name of the team and its position in the leauge */ return "Team ". $teamData["team"] ." are currently number " . $teamData["position"] . " in the league " ; } function getResults($teamData){ /*This function takes an array of team data and returns a string containing the results of the team */ return $teamData["team"] ." have won " . $teamData["won"] . " , drawn " . $teamData["drew"] . " , and lost " . $teamData["lost"] . " games to date " ; } function getPoints($teamData){ /*This function takes an array of team data and returns a string containing the points and calculates the old two points system */ $oldpoints = $teamData["won"] * 2 + $teamData["drew"]; return $teamData["team"] ." have " . $teamData["points"] . " points under the current system " . "<br> Under two points for a win they would have " . $oldpoints ; } function getDifference($teamData){ /*This function takes an array of team data and returns a string containing the name of the team and its goal difference in the leauge */ return $teamData["team"] ." goal difference is " . $teamData["difference"] . " at the moment " ; } function getTeamData($team, $tablesPage){ /* This function takes a webpage url and the name of a team as two string arguments. e.g. getTeam(""http://www.bbc.com/sport/football/tables", "liverpool") It returns an array of data about the team. You don't need to understand what this function does just that it returns an array which contains keya and values. The values map to the following keys: "position", "team", "played", "won", "drew", "lost", "for", "against", "difference", "points" */ $html = new DOMDocument(); @$html->loadHtmlFile($tablesPage); //use DOM @$xpath = new DOMXPath($html); //use XPath $items = $xpath->query('//td/a[text()="' . $team . '"]/../..'); //get the relevant table row $values[] = array(); foreach($items as $node){ foreach($node->childNodes as $child) { if($child->nodeType == 1) array_push($values, $child->nodeValue); //KLUDGE } } $values[2] = substr($values[2], -1); //KLUDGE $values = array_slice( $values, 2, count($values)-4); //KLUDGE $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" multiple="multiple" size="3" <option value=""></option> <option value="Everton">Everton</option> <option value="Arsenal">Arsenal</option> <option value="Chelsea">Chelsea</option> <option value="Man Utd">Man Utd</option> <option value="Liverpool">Liverpool</option> </select> <select name="data"> <option value="position">position</option> <option value="results">results</option> <option value="two points for a win">two points for a win</option> <option value="goal difference">goal difference</option> <select> <input type="submit" value="Get Data"></input> </select> </form> </body> </html>
×
×
  • 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.