Hello,
Sorry for my english I live in France
I have two questions where I don't know how I can resolve this.
I want to show in a select list all the fields which are on my xml feed.
I try to do this in the foreach
echo "<select><option value='".$key."'>".$key."</option></select>";
but it show me one value only in my list.
Then, I want to know how I can insert the value of a second field to a sql database.
José
function myRecordHandler($record)
{
print "<table border='1'>";
foreach($record as $key => $value)
{
print "<tr>";
print "<th>".$key."<select>";
echo "<option value='".$key."'>".$key."</option>";
echo "</select></th>";
print "<td>".htmlentities($value)." </td>";
print "</tr>";
}
print "</table>";
// return a non-zero value to stop reading any more records
return 0;
}
MagicParser_parse($filename,"myRecordHandler",$format);
Hello José,
Your select list is being broken I think by the closing select tag within your foreach loop - that is most likely the only problem... Have a go with your myRecordHandler function like this:
function myRecordHandler($record)
{
print "<table border='1'>";
print "<tr>";
print "<td>";
print "<select>";
foreach($record as $key => $value)
{
print "<option value='".htmlentities($key)."'>".htmlentities($value)."</option>";
}
print "</td>";
print "</tr>";
print "</table>";
// return a non-zero value to stop reading any more records
return 0;
}
I'm assuming that you want the $key as the option value, and the value displayed as the option (if that makes sense!). Don't forget that in order to read the value of the SELECT box (which must be part of a form) you will need to give it a name, for example:
print "<select name='mySelectBox'>";
Hope this helps,
Cheers,
David.