dynamic population of a select list from a text file












0














I have a website that allows the user to query a database by selecting values in three dropdowns.



Currently, I populate the select list using a single text file. However, there is a design change and now we want to populate the second drop-down using the entry selected in the first drop-down. I know it is not very uncommon to do this but I am very new to website design and need some guidance. I have not come across any example which uses just a simple text file and reads it the way I am currently doing.



So, when a user selects an Application from the first select list, the corresponding configuration should get loaded in the second select box. For every application, I have a configuration file associated with it e.g app1_config.txt, app2_config.txt and so on. I know, I have to use some event listener and then may be used a switch case to do mapping of app name to correct config file and then read the file the same way I am doing now. Can somebody please guide me on this. Most of the examples I saw online were using ajax/json/database etc. Can I really implement the desired dynamic loading with minimal changes to my current approach? I really need to use all the text files for populating the select list.



e.g. App1_config.txt will have entries like:



config1
config2
config3
config4


Here is what my php code looks like:



<body>
<div id = header>
<div class = container> Database Query </div>
</div>
<div class = container>
<form action="""" method = "post">
//populating first dropdown using text file
<?php
$filename='/path/to/the/text/file.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param1>
<p align="top"><b> Application: </b></p>

<select size=15 name = "App" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
<?php
$filename='db_report_cfg_string.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param2>
<p align="top"><b> Configuration: </b></p>

<select size=15 name = "Config" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
//some code to populate another select list and provide email address (not shown here)


<?php
if(isset($_POST['submit'])){
$varApp= $_POST['App'];
$varConfig = $_POST['Config'];
$varCtrType = $_POST['CtrType'];
$varEmail = $_POST['mailid'];
//some processing based on values provided by user.
exec("/py $varApp $varConfig $varCtrType 2>&1",$output );
if ($output[8] == "Empty"){
echo "<div style ='font:22px Arial,tahoma,sans-serif;color:#ff0000'><br>No Data Available! <br></div>";
}
else {
exec(' printf "Please find attached the query result for following selection:nnApp: '.$varApp.' nConfig: '.$varConfig.' nCounter Type: '.$varCtrType.' nn Thanks! " | /bin/mail -s "Database Query Result" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
echo "<div style ='font: 18px Arial,tahoma,sans-serif;color:#10ac84'><br><b> Please check your email for result !<b> <br>";
echo '<script language="javascript">';
echo 'alert("Please check your email for result! Submitted Query details: Selected App: '.$varAPP.' Configuration:")';
echo '</script>';
}
$_POST=array();

}
?>


</body>


I deeply appreciate your guidance here.










share|improve this question
























  • Do you want to create dropdown from text files?
    – Gufran Hasan
    Nov 21 '18 at 8:39










  • /path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
    – Twinkle
    Nov 21 '18 at 8:41












  • Gurfan Hasan: Yes
    – Aisha
    Nov 21 '18 at 17:49










  • Twinkle: that file is in current directory so no need to specify full path
    – Aisha
    Nov 21 '18 at 17:50
















0














I have a website that allows the user to query a database by selecting values in three dropdowns.



Currently, I populate the select list using a single text file. However, there is a design change and now we want to populate the second drop-down using the entry selected in the first drop-down. I know it is not very uncommon to do this but I am very new to website design and need some guidance. I have not come across any example which uses just a simple text file and reads it the way I am currently doing.



So, when a user selects an Application from the first select list, the corresponding configuration should get loaded in the second select box. For every application, I have a configuration file associated with it e.g app1_config.txt, app2_config.txt and so on. I know, I have to use some event listener and then may be used a switch case to do mapping of app name to correct config file and then read the file the same way I am doing now. Can somebody please guide me on this. Most of the examples I saw online were using ajax/json/database etc. Can I really implement the desired dynamic loading with minimal changes to my current approach? I really need to use all the text files for populating the select list.



e.g. App1_config.txt will have entries like:



config1
config2
config3
config4


Here is what my php code looks like:



<body>
<div id = header>
<div class = container> Database Query </div>
</div>
<div class = container>
<form action="""" method = "post">
//populating first dropdown using text file
<?php
$filename='/path/to/the/text/file.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param1>
<p align="top"><b> Application: </b></p>

<select size=15 name = "App" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
<?php
$filename='db_report_cfg_string.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param2>
<p align="top"><b> Configuration: </b></p>

<select size=15 name = "Config" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
//some code to populate another select list and provide email address (not shown here)


<?php
if(isset($_POST['submit'])){
$varApp= $_POST['App'];
$varConfig = $_POST['Config'];
$varCtrType = $_POST['CtrType'];
$varEmail = $_POST['mailid'];
//some processing based on values provided by user.
exec("/py $varApp $varConfig $varCtrType 2>&1",$output );
if ($output[8] == "Empty"){
echo "<div style ='font:22px Arial,tahoma,sans-serif;color:#ff0000'><br>No Data Available! <br></div>";
}
else {
exec(' printf "Please find attached the query result for following selection:nnApp: '.$varApp.' nConfig: '.$varConfig.' nCounter Type: '.$varCtrType.' nn Thanks! " | /bin/mail -s "Database Query Result" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
echo "<div style ='font: 18px Arial,tahoma,sans-serif;color:#10ac84'><br><b> Please check your email for result !<b> <br>";
echo '<script language="javascript">';
echo 'alert("Please check your email for result! Submitted Query details: Selected App: '.$varAPP.' Configuration:")';
echo '</script>';
}
$_POST=array();

}
?>


</body>


I deeply appreciate your guidance here.










share|improve this question
























  • Do you want to create dropdown from text files?
    – Gufran Hasan
    Nov 21 '18 at 8:39










  • /path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
    – Twinkle
    Nov 21 '18 at 8:41












  • Gurfan Hasan: Yes
    – Aisha
    Nov 21 '18 at 17:49










  • Twinkle: that file is in current directory so no need to specify full path
    – Aisha
    Nov 21 '18 at 17:50














0












0








0







I have a website that allows the user to query a database by selecting values in three dropdowns.



Currently, I populate the select list using a single text file. However, there is a design change and now we want to populate the second drop-down using the entry selected in the first drop-down. I know it is not very uncommon to do this but I am very new to website design and need some guidance. I have not come across any example which uses just a simple text file and reads it the way I am currently doing.



So, when a user selects an Application from the first select list, the corresponding configuration should get loaded in the second select box. For every application, I have a configuration file associated with it e.g app1_config.txt, app2_config.txt and so on. I know, I have to use some event listener and then may be used a switch case to do mapping of app name to correct config file and then read the file the same way I am doing now. Can somebody please guide me on this. Most of the examples I saw online were using ajax/json/database etc. Can I really implement the desired dynamic loading with minimal changes to my current approach? I really need to use all the text files for populating the select list.



e.g. App1_config.txt will have entries like:



config1
config2
config3
config4


Here is what my php code looks like:



<body>
<div id = header>
<div class = container> Database Query </div>
</div>
<div class = container>
<form action="""" method = "post">
//populating first dropdown using text file
<?php
$filename='/path/to/the/text/file.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param1>
<p align="top"><b> Application: </b></p>

<select size=15 name = "App" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
<?php
$filename='db_report_cfg_string.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param2>
<p align="top"><b> Configuration: </b></p>

<select size=15 name = "Config" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
//some code to populate another select list and provide email address (not shown here)


<?php
if(isset($_POST['submit'])){
$varApp= $_POST['App'];
$varConfig = $_POST['Config'];
$varCtrType = $_POST['CtrType'];
$varEmail = $_POST['mailid'];
//some processing based on values provided by user.
exec("/py $varApp $varConfig $varCtrType 2>&1",$output );
if ($output[8] == "Empty"){
echo "<div style ='font:22px Arial,tahoma,sans-serif;color:#ff0000'><br>No Data Available! <br></div>";
}
else {
exec(' printf "Please find attached the query result for following selection:nnApp: '.$varApp.' nConfig: '.$varConfig.' nCounter Type: '.$varCtrType.' nn Thanks! " | /bin/mail -s "Database Query Result" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
echo "<div style ='font: 18px Arial,tahoma,sans-serif;color:#10ac84'><br><b> Please check your email for result !<b> <br>";
echo '<script language="javascript">';
echo 'alert("Please check your email for result! Submitted Query details: Selected App: '.$varAPP.' Configuration:")';
echo '</script>';
}
$_POST=array();

}
?>


</body>


I deeply appreciate your guidance here.










share|improve this question















I have a website that allows the user to query a database by selecting values in three dropdowns.



Currently, I populate the select list using a single text file. However, there is a design change and now we want to populate the second drop-down using the entry selected in the first drop-down. I know it is not very uncommon to do this but I am very new to website design and need some guidance. I have not come across any example which uses just a simple text file and reads it the way I am currently doing.



So, when a user selects an Application from the first select list, the corresponding configuration should get loaded in the second select box. For every application, I have a configuration file associated with it e.g app1_config.txt, app2_config.txt and so on. I know, I have to use some event listener and then may be used a switch case to do mapping of app name to correct config file and then read the file the same way I am doing now. Can somebody please guide me on this. Most of the examples I saw online were using ajax/json/database etc. Can I really implement the desired dynamic loading with minimal changes to my current approach? I really need to use all the text files for populating the select list.



e.g. App1_config.txt will have entries like:



config1
config2
config3
config4


Here is what my php code looks like:



<body>
<div id = header>
<div class = container> Database Query </div>
</div>
<div class = container>
<form action="""" method = "post">
//populating first dropdown using text file
<?php
$filename='/path/to/the/text/file.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param1>
<p align="top"><b> Application: </b></p>

<select size=15 name = "App" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
<?php
$filename='db_report_cfg_string.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<div id = param2>
<p align="top"><b> Configuration: </b></p>

<select size=15 name = "Config" required>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
</p>
</div>
//some code to populate another select list and provide email address (not shown here)


<?php
if(isset($_POST['submit'])){
$varApp= $_POST['App'];
$varConfig = $_POST['Config'];
$varCtrType = $_POST['CtrType'];
$varEmail = $_POST['mailid'];
//some processing based on values provided by user.
exec("/py $varApp $varConfig $varCtrType 2>&1",$output );
if ($output[8] == "Empty"){
echo "<div style ='font:22px Arial,tahoma,sans-serif;color:#ff0000'><br>No Data Available! <br></div>";
}
else {
exec(' printf "Please find attached the query result for following selection:nnApp: '.$varApp.' nConfig: '.$varConfig.' nCounter Type: '.$varCtrType.' nn Thanks! " | /bin/mail -s "Database Query Result" -a '.$output[8].' '.$varEmail.' 2>&1', $output2 );
echo "<div style ='font: 18px Arial,tahoma,sans-serif;color:#10ac84'><br><b> Please check your email for result !<b> <br>";
echo '<script language="javascript">';
echo 'alert("Please check your email for result! Submitted Query details: Selected App: '.$varAPP.' Configuration:")';
echo '</script>';
}
$_POST=array();

}
?>


</body>


I deeply appreciate your guidance here.







php file web dynamic dropdown






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 3:05









Funk Forty Niner

80.5k1247101




80.5k1247101










asked Nov 21 '18 at 8:34









AishaAisha

154




154












  • Do you want to create dropdown from text files?
    – Gufran Hasan
    Nov 21 '18 at 8:39










  • /path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
    – Twinkle
    Nov 21 '18 at 8:41












  • Gurfan Hasan: Yes
    – Aisha
    Nov 21 '18 at 17:49










  • Twinkle: that file is in current directory so no need to specify full path
    – Aisha
    Nov 21 '18 at 17:50


















  • Do you want to create dropdown from text files?
    – Gufran Hasan
    Nov 21 '18 at 8:39










  • /path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
    – Twinkle
    Nov 21 '18 at 8:41












  • Gurfan Hasan: Yes
    – Aisha
    Nov 21 '18 at 17:49










  • Twinkle: that file is in current directory so no need to specify full path
    – Aisha
    Nov 21 '18 at 17:50
















Do you want to create dropdown from text files?
– Gufran Hasan
Nov 21 '18 at 8:39




Do you want to create dropdown from text files?
– Gufran Hasan
Nov 21 '18 at 8:39












/path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
– Twinkle
Nov 21 '18 at 8:41






/path/to/the/text/ missing in $filename='db_report_cfg_string.txt';
– Twinkle
Nov 21 '18 at 8:41














Gurfan Hasan: Yes
– Aisha
Nov 21 '18 at 17:49




Gurfan Hasan: Yes
– Aisha
Nov 21 '18 at 17:49












Twinkle: that file is in current directory so no need to specify full path
– Aisha
Nov 21 '18 at 17:50




Twinkle: that file is in current directory so no need to specify full path
– Aisha
Nov 21 '18 at 17:50












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408023%2fdynamic-population-of-a-select-list-from-a-text-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408023%2fdynamic-population-of-a-select-list-from-a-text-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin