
bishmedia
Members-
Posts
21 -
Joined
-
Last visited
Everything posted by bishmedia
-
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
-
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>"; } ?>
-
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; } ?>
-
How do i fit this in to my current file :-(
-
ive attached both files so you can see what i mean :-) xmldata.xml resulttest.php
-
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>
-
Thats great, many thanks.... you make it look so easy
-
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
-
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>
-
Yes thats fine i just thought id ask, but not to worry excel has just answered all my prayers!!!!
-
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
-
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
-
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 :-)
-
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>"; } ?>
-
Thats perfect, i would like to thank you ver much for your help today :-)
-
Ok that works fine many thanks, just one last question when you load the page the select is there followed b an error... Notice: Undefined index: bandName in \xmltest.php on line 27 But once i select a band it goes away and shows results... Whats the best way of getting rid of this error when the page loads?? Oh, and your great :-)
-
Many thanks for your help today Barand Ive put together below what youve done for me today, the select is now working but the $search string is throwing up and error... Notice: Undefined variable: search in xmltest.php on line 27 How should the $search string be?? <?php function getOptions($file, $element) { $xml = simplexml_load_file($file); $results = $xml->xpath("//result/$element"); $results = array_unique($results); $options = "<option value=''>- select $element -</option>\n"; foreach($results as $res) { $options .= "<option value='{$res}'>{$res}</option>\n"; } return $options; } ?> <form method="post"> <select name="bandName"> <?php echo getOptions('xmltestdata.xml', 'bandName')?> </select> <br> <input type="submit" name="btnSubmit" value="Search"> </form> <?php $xml = simplexml_load_file('xmltestdata.xml'); $search = ???? //This is line 27 $results = $xml->xpath("//result[bandName='$search']"); foreach ($results as $res) { echo "$res->compName $res->year $res->position <br>"; } ?> Many thanks in advance
-
I'll have to try and build a form then, i better get googling Many Thanks
-
How do i get the value from a combobox to view certain xml files??? <p>Competitions<br> <select name="select"> <option value="Option 1" selected>Butlins Mineworkers</option> <option value="Option 2">West Midlands Area</option> <option value="Option 3">Wales Area</option> <option value="Option 4">Scotland Areas</option> </select> </p> <?php $xml = simplexml_load_file('xmltestdata.xml'); $search = ****above value*** $results = $xml->xpath("//result[compName='$search']"); echo "<u><b>$search</b></u><br /><br />"; foreach ($results as $res) { echo "$res->bandName $res->year $res->position <br>"; } ?> Sorry if im being thick but i a newbie :-p Many Thanks in advance :-)
-
Many many thanks, that brilliant, i will try this later and move on to another problem im sure :-)
-
ok all you phpfreaks, im hoping one of you can help me :-) ive started a simple xml file and php file to read and view as below.... <?xml version="1.0" encoding="ISO-8859-1"?> <datas> <comp> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>GUS Virtuoso</bandName> <position>1st</position> <points>2</points> </result> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>GUS Virtuoso</bandName> <position>2nd</position> <points>4</points> </result> <result> <year>2013</year> <compName>Butlins Mineworkers</compName> <bandName>Carlton Main Frickley Colliery</bandName> <position>3rd</position> <points>6</points> </result> </comp> </datas> <?php $xml = simplexml_load_file("xmltestdata.xml") or die("Error: Cannot create object"); foreach($xml->children() as $result){ foreach($result->children() as $result => $data){ echo $data->year; echo $data->compName; echo $data->bandName; echo $data->position; echo $data->points; echo "<br />"; } } ?> In time the xml will grow and my question is, what if a user wanted to view results for a specific band 'bandName' via say a 'Drop Down Box?? I do hope theres someone out there in cyber who can help Many Thanks in advance. Bish