Jump to content

bishmedia

Members
  • Posts

    21
  • Joined

  • Last visited

About bishmedia

  • Birthday 08/02/1963

Profile Information

  • Gender
    Male
  • Location
    Rushden

bishmedia's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok thanks for your time, i was just about to approach it in 2 different ways.. 1) The XML is built with Excel so i can sort by that column. 2) Putting the results into an array
  2. Its not loading anything from the xml file??? <?php function cmp($a,$b ) { return strcmp($a, $b ); } function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/$element"); usort($results, 'cmp'); $options = "\n"; foreach($results as $res) { $options .= "\n"; } return $options; } ?> <form method="post" name="Band"> <select name="bandName"> <?php echo getOptions('xmldata.xml', 'bandName')?> </select> <input type="submit" name="btnSubmit" value="Search"> </form> <?php if (isset($_POST['btnSubmit'])) { $xml = simplexml_load_file('xmldata.xml'); $search = $_POST['bandName']; $results = $xml->xpath("//result[bandName='$search']"); echo "$search <br />"; echo "<table>"; echo "<tr>"; echo "<td>"; foreach ($results as $res) { echo "$res->year</td> <td style=\"width:175px\">$res->compName</td> <td style=\"width:175px\">$res->section</td><td>$res->position"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; } echo "</table>"; } ?>
  3. Im pulling my hair out with this and wished id stayed with VB from the start, ive tried various combinations with no success... <?php function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/bandName"); usort($results, 'cmp'); $options = "<option value=''>- Choose Band Name -</option>\n"; function cmp($a,$b ) { return strcmp($a, $b ); } foreach($results as $res) { $options .= "<option value='{$res}'>{$res}</option>\n"; } return $options; } ?>
  4. How do i fit this in to my current file :-(
  5. ive attached both files so you can see what i mean :-) xmldata.xml resulttest.php
  6. I'm trying to sort some data drawn from an XML file but i just cant figure out how to do this?? Can anyone help?? <?php function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/$element"); $results = array_unique($results); $options = "<option value=''>- Choose Band Name -</option>\n"; foreach($results as $res) { $options .= "<option value='{$res}'>{$res}</option>\n"; } return $options; } ?> <form method="post" name="Band"> <select name="bandName"> <?php echo getOptions('xmldata.xml', 'bandName')?> </select> <input type="submit" name="btnSubmit" value="Search"> </form>
  7. Thats great, many thanks.... you make it look so easy
  8. Ive attached the xml so you can see what i mean, each final result will have the same date. Im not 100% sure on what best for this but evertime i try something i screw it up and have to go back to te original, i tougt if you have the end result it would be easy grabbing the date parameter? xmldata.xml
  9. Ive added a new parameter in the xml file called 'date' but for the life of me i cant figure out how to add it to a title highlighted in red below, xml file is like below.. [b]<result>[/b] [b]<year>2013</year>[/b] [b]<date>19th January 2013</date>[/b] [b]<compName>Butlins Mineworkers</compName>[/b] [b]<section>First</section>[/b] [b]<bandName>Stannington Brass</bandName>[/b] [b]<position>12</position>[/b] [b]<conductor>Geoff Hawley</conductor>[/b] [b]</result>[/b] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include("../includes/head.php"); ?> <title>Competition Results - Rushden Windmill Band</title> <link href="../stylesheet/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div style="padding:10px 10px 10px 10px"> <hr /> <h1>Competition Database</h1> <hr /> <h4> <?php function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/$element"); foreach ($results as &$v) $v = (string)$v; $results = array_unique($results); sort($results); $options=''; foreach($results as $res) { $selected=''; if (isset($_POST[$element])) $selected = $res==$_POST[$element] ? 'selected="selected"' : ''; $options .= "<option $selected value='{$res}'>{$res}</option>\n"; } return $options; } ?> <form method="post"> <select name="compName"> <option value=''>- select competition -</option> <?php echo getOptions('xmldata.xml', 'compName')?> </select> <select name="section"> <option value=''>- select section -</option> <?php echo getOptions('xmldata.xml', 'section')?> </select> <select name="year"> <option value=''>- select year -</option> <?php echo getOptions('xmldata.xml', 'year')?> </select> <input type="submit" name="btnSubmit" value="Search"> </form> <?php $searcharray = array(); $search = ''; if (isset($_POST['compName']) && $_POST['compName']) { $searcharray[] = "[compName={$_POST['compName]}']"; } if (isset($_POST['section']) && $_POST['section']) { $searcharray[] = "[section={$_POST['section]}']"; } if (isset($_POST['year']) && $_POST['year']) { $searcharray[] = "[year={$_POST['year]}']"; } $search = join('', $searcharray); if ($search) { $xml = simplexml_load_file('xmldata.xml'); $results = $xml->xpath("//result$search"); if ($results) { echo "<h4><u>{$_POST['compName']} - {$_POST['section']} Section - {$_POST['year']}</u></h4>"; <--- Title to include Date echo "<table>"; foreach ($results as $res) { echo "<tr><td>$res->position</td><td>$res->bandName</td> <td style=\"width:175px\">$res->conductor</td> </tr>"; } echo "</table>"; } else { echo "<p>No matching results</p>"; } } else { echo "<p>Please enter search criteria</p>"; } ?> </h4> <hr /> </div> </body> </html>
  10. Yes thats fine i just thought id ask, but not to worry excel has just answered all my prayers!!!!
  11. Sadly I haven't tried anything, I was hoping there was some software somwhere. I'm hoping someone can help me with a simple php form that has text boxes for the data. I'm gonna have a go later if I can
  12. Ok i want to build a large database but find it very repetitive in having to keep typing the xml child & data.. Does anyone know of any software that would make this easier or PHP code to write the following plus the data in a form and add it to the end of an existing xml form??? <result> //child <year></year> <compName></compName> <bandName></bandName> <position></position> <conductor></conductor> </result> Many thanks in advance
  13. Ok coulnt wait to get home from work to try this guess what... it works :-) Once again many thanks, in the future i would like to try and change the look and perhaps have an auto select instead of a search button :-)
  14. Ive changed everything to view by competition now, great. How easy is it to change to have two combo boxes, one for compName and one for year and the results show this effect?? <?php function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/$element"); $results = array_unique($results); $options = "<option value=''>- Choose Competition -</option>\n"; foreach($results as $res) { $options .= "<option value='{$res}'>{$res}</option>\n"; } return $options; } ?> <form method="post" name="Band"> <select name="compName"> <?php echo getOptions('xmldata.xml', 'compName')?> </select> <input type="submit" name="btnSubmit" value="Search"> </form> <?php if (isset($_POST['btnSubmit'])) { $xml = simplexml_load_file('xmldata.xml'); $search = $_POST['compName']; $results = $xml->xpath("//result[compName='$search']"); echo "$search <br />"; echo "<table>"; echo "<tr>"; echo "<td>"; foreach ($results as $res) { echo "$res->bandName</td> <td style=\"width:175px\">$res->conductor</td> <td>$res->position"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>"; } echo "</table>"; } ?>
  15. Thats perfect, i would like to thank you ver much for your help today :-)
×
×
  • 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.