Wrap all your php code in php bb-code tags, html code in html tags and other code in code tags. Also always indent your code.
a4amruta;10989489 wrote:
I have a requirement to add <option>user$template<option> to existing <Select> tag in showmenuitem.php from useredit .php
Why do you need to store this data permanentely in showmenuitem.php? Also, since what you want to do seems to be related to each specific user, while you have only one single file, how will you know that 2+ people aren't accessing this file at the same time (problem known as race condition).
Why not rather do it like this
useredit.php
# whatever else is done in useredit.php as before.
$userOptions = array('user' => 'option', 'data' => 'here');
require 'showmenuitem.php';
showmenuitem.php
<!-- stuff above as before -->
<select class="other" name="template" id="template" >
<option>Select..</option>
<option>userja_purity</option>
<option>rhuk_milkyway</option>
<option>ja_purity</option>
<option>rt_novus_j15</option>
<option>iyosisj1</option>
<option>beez</option>
<option>themza_j15_12</option>
<option>dealer1_ rhuk_milkyway</option>
<option>dealer1themza_j15_12</option>
<?php
foreach ($userOptions as $val => $opt)
{
printf('%s<option value="%s">%s</option>%s',
"\t",
htmlentities($val, ENT_QUOTES, 'utf-8'),
htmlentities($opt, ENT_QUOTES, 'utf-8'),
"\n"
);
}
?>
</select>
<!-- stuff below as before -->
Also, if you output an entire web page, why do you call the file showmenuitem? It doens't show a menu item, or even an entire menu - it shows an entire page.
You really should do it as shown above, but just to explain what goes wrong here...
$doc = new DOMDocument();
# Don't try to load a php file as if it was an html file. It isn't. It might output an
# html document, but for that to happen, you have to actually run it through the php
# interpreter.
# $doc->loadHTMLFile("C:/xampp/htdocs/joomla1.5/components/com_amruta_showmenuitems/showmenuitems.php");
# You should instead make showmenuitems.php return a string containing
# the html code, and then you can
$html = require '/path/to/showmenuitem.php';
$doc->loadHTML($html);
# Where in the php docs for DOMDocument do you find Document::options?
# See: http://se2.php.net/manual/en/class.domdocument.php
# $doc->option = 'this will not work';
# You need to get a reference to the select element
$el = $doc->getElementById('template');
# And then use pretty much the same approach as shown above, using an array
# to loop over the data to add
for ($userOptions as $val => $opt)
{
$o = $doc->createElement('option');
$o->setAttribute('value', $val);
$t = $doc->createTextNode($opt);
$o->appendChild($t);
$el->appendChild($o);
}