拉出simplexml并将它们解析为php变量。我有一个包含数组的表单。我想要一个窗体外的按钮,它将“基本上”转到相同的形式但是使用下一个数组编号。 IE:
<?
if( $xml = simplexml_load_file('my.xml') ) {
foreach( $xml as $SAVED_EXPORT) {
$mfg = $SAVED_EXPORT->productmanufacturer;
}
}
?>
<form id="myform" method="post" action="coderdb.php">
<input type="text" value="<? echo $mfg[0] ?>" name="MFG" />
<input type="submit" />
</form>
我想要一个按下NEXT的按钮,当点击它时会拉出下一个数组,即。 $mfg[1]
。我相信页面必须重新加载,这很好。我读过某个地方,我可能不得不使用$key
,但从未使用过,我不确定它在这里需要什么。
答案 0 :(得分:0)
你需要一些javascript使用JQuery。
<script type="text/javascript">
$(function(){
var array = [];
<?
if( $xml = simplexml_load_file('my.xml') ) {
$i=0;
foreach( $xml as $SAVED_EXPORT) {
$mfg = $SAVED_EXPORT->productmanufacturer;
}
}
foreach($mgf as $key=$value) {
// if $key in not numeric then add iterator for this foreach
echo "array[$key]=$value";
}
?>
iterator = 0;
$('#nextExport').click(function(){
var theInput = $('#setExport');
// theInput.attr('val',array[iterator]);
theInput.val(array[iterator]);
if(iterator==array.length) {
iterator = -1;
}
iterator++;
});
});
</script>
<form id="myform" method="post" action="coderdb.php">
<input type="text" id="setExport" value="<? echo $mfg[0] ?> name="MFG" />
<input type="button" id="nextExport" value="Next Export" />
<input type="submit" />
</form>
我希望这会有所帮助。如果出现问题,请检查语法,逻辑是正确的。
答案 1 :(得分:0)
您需要一种方法来跟踪您所在的数组索引,因为截至目前您只将其设置为静态数字0
。因此,如果您添加一个隐藏的表单,您可以让它发布您当前所在的值,然后使用PHP,您可以在显示新表单之前递增它。您的表单也应该指向它所在的PHP文档。
<?
if( $xml = simplexml_load_file('my.xml') ) {
foreach( $xml as $SAVED_EXPORT) {
$mfg = $SAVED_EXPORT->productmanufacturer;
}
}
if(isset($_POST["index"])) $index = $_POST["index"] + 1;
else $index = 0;
?>
<form id="myform" method="post" action="coderdb.php">
<input type="hidden" value="<? echo $index ?>" name="index" />
<input type="text" value="<? echo $mfg[$index] ?>" name="MFG" />
<input type="submit" />
</form>