Click to See Complete Forum and Search --> : Please help me???
I want to execute the following menu as many times as the user want. Please take a look and give me some suggestion.
First the user will be asked the number of time he/she wants to execute the menu bar in the same page (without opening a new page).
Please help me???
<form action="InsertFunctionComponent.php" method="GET">
<br><br><b>How many times you want</b>
<input type="text" name="number" Size = "30">
<br><br>
<?php
if($submit)
{
?>
<br>Select any of the following Function<br><br>
<select name = "FunctionMenu" Multiple>
<?php
foreach ($Function_Name as $Existing_Function)
print " <option value=\"$Existing_Function \">$Existing_Function</option>";
?>
</select>
<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="Reset">
</form>
<?php
}
else
{
---do something---
}
?>
Can't you just use a for loop?
Thank you for your suggestion. But I think I could not make myself clear to you. I am going to tell you indetail about my plan or goal.
First of all user will be asked a number of rows. Suppose user choose 3. And then the memu will be appear onece and user will select one or more item from that menu and hit submit. Those items will be stored in one row of mysql data base table. Then the same menu will be apeared to the screen second time and user will do the same and it will go for 3rd time as user chose the number 3 at the begining.After that I will use those items for my next operation. Let me know if you understand my problem. Some code for the necessary steps will be appriciated. Thank you.
Phil Karras
08-11-2003, 02:56 PM
I see you're posting here as well as JSworkshop.com. The info you've given here is a bit more helpful, but still not really clear enough, at least for me, to be able to help.
I've re-written your posting to see if I understand it, please
confirm that I have the correct understanding of what it is you
want to do.
First of all the user will be asked for the number of entries he
wants to make.
Example: the user chooses 3.
The memu will appear the first time and the user will
select one or more item from that menu and hit submit.
The selected items will be stored in one row of my mysql data
base table.
Then the same menu will apear on the screen a second time and
user selects another item (or items) and again it goes to the database and
again for 3rd time the menu appears and the user selects from the
menu a third and final time, submits and the data is again placed
in the database.
After that I will use those items for my next operation. Let me
know if you understand my problem. Some code for the necessary
steps will be appriciated. Thank you.
Thank you Mr. Phil Karras. You are absolutely right.
Phil Karras
08-11-2003, 04:06 PM
OK, good. I will say that this seems overly complex to me. Why would someone want to select from the same list of items more than once? Why do you want this to be done? What is the advantage, purpose?
What you'll need to do is to keep that number & decrement it as you go through the submittal process and then back to the "menu."
The first time the client submits you just get the number, decrement it once, & set up the first menu.
Now the number is "hidden" & I'd remove the number field from the form as well.
Once the user submits the form the number is decremented again and the data saved in the DB and the form is sent to the client again.
Etc till we reach number < 0 at which time you now do that something else you wanted to do.
This is just one possible way to do it.
Here's perhaps a simpler way:
Don't ask for the number of times the client wants to fill out the form but rather put the complete form up & when submitted save the data in the DB & then put a page up that asks if the client wants to do it again. If yes, put the form up again and get the data put it in to the DB again, and then ask again.
In this way the programming is much easier and it does the same thing.
Using this method you could break it apart into two simple PHP programs that keep calling each other till the client is done & says "NO" I don't want to enter any more.
I tried the following code. But does not work according to my goal. Could you please take a look. I am new in web designing so please bear with me. Thank you.
<?php
$Function_Name = array("function1", "function 2", "function 3", "function 4");
if (isset($_GET['number']))
{
for ($i = 0; $i < $_GET['number']; $i++)
{
print $_GET['FunctionMenu'];
} // if number set
}
else
{ // else number not set
?>
<form action="menutest5.php" method="GET">
<br><br><b>How many times you want</b>
<input type="text" name="number" Size = "30">
<br><br>
<br>Select any of the following Function<br><br>
<select name = "FunctionMenu" Multiple>
<?php
foreach ($Function_Name as $Existing_Function)
print " <option value=\"$Existing_Function \">$Existing_Function</option>";
?>
</select>
<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="Reset">
</form>
<?php
} // else number not set
?>
I tried the following code but I am not getting the output that I am looking for. I want one menu at a time and after pressing the submit button another menu (same one) will be appeared in the same place if user choose 2 as number. Plese give me some suggestion.
<?php
if($submit != "submit" || $submit != "send")
{
print "<form action=\"index.php\" method=\"GET\">";
print "<p>Enter in the number of times below:</p>";
print "<input type=\"text\" name=\"number\" size=\"30\">";
print "<input name=\"submit\" type=\"submit\" value=\"send\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>";
}
if ($submit == "send")
{
$main_count = 1;
$months = array("January","February","March","April","May","June","July",
"August","September","October","November","December");
$number = $HTTP_GET_VARS["number"];
print "<form action=\"index.php\" method=\"GET\">";
while($main_count <= $number)
{
print "<select name=\"something\" value=\"$main_count\" multiple";
for ($x_f=0; $x_f<=count($months); $x_f++)
{
print "\t<option value=\"$x_f\">".$months[$x_f-1]."\n";
reset($months);
}
print "</select>";
print "<br>";
$main_count++;
}
print "<input name=\"submit\" type=\"submit\" value=\"submit\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>";
}
if ($submit == "submit")
{
//you insert all of the data from the form element into the DB here
//make sure to use $HTTP_GET_VARS[""]; for you variables
print "Hello World";
}
?>
Phil Karras
08-11-2003, 09:41 PM
I gave an over-all view of how to design what you wanted to the best of my understanding. (In fact I gave you two different designs.) I simply do not have the time to actually write the code for you, unless you're willing to contact me as a consultant & pay for my time.
I suggest that you keep at it & I'm sure you will figure it out.
Have you tried the two (or more) file system I suggested? I really think that would be the easy way to do it.
I fixed that problem. Now trying to get the user selection after all menu has been shown to the user and when the selections are done. Could you please let me know how to get all those information at the end. The way I did it just work for the last menu selection. I suppose I have to use some sort of array but don't know exactly how to do that. I will appriciate your suggestion. Thank you.
Take a look of my complete code:
<html>
<title>
Menu Test
</title>
<body>
<script type="text/javascript">
<!--
function updateTextBox(selectObj, textBoxObj)
{
var index = selectObj.selectedIndex;
var selection = selectObj.options[index].text;
textBoxObj.value += selection + "\n";
}
// -->
</script>
<?php
extract( $_GET );
if( !isset($submit))// do this if no GET vars
{
print "<form method=\"GET\">";
print "<p>Enter in the number of times below:</p>";
print "<input type=\"text\" name=\"number\" size=\"30\">";
$menu_counter = 0;
print "<input type='hidden' name='menu_counter' value=$menu_counter>";
print "<input name=\"submit\" type=\"submit\" value=\"send\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>" ;
}
else
{
/*if( $submit='submit' )
{
//you insert all of the data from the form element into the DB here
//make sure to use $HTTP_GET_VARS[""]; for you variables
print "Hello World";
} */
//$menu_counter = 0;
//print "<form name = \"myform\" action=\"CheckInsertedItems.php\" method=\"POST\">";
if( $number>0 )
{
$months = array("January","February","March","April","May","June","July", "August","September","October","November","December");
$number = $HTTP_GET_VARS["number"]-1;
$menu_counter =$HTTP_GET_VARS["menu_counter"]+1;
print "<form method=\"GET\">";
print "Select components for term $menu_counter<br>";
//print "<select name=\"something\" value=\"$main_count\" multiple";
//for ($i=0; $i<=count($months); $i++)
?>
<select size="5" name="user_choice" onclick="updateTextBox(this, currentSelections)">
<?php
foreach ($months as $Existing_Item)
{
//print "\t<option value=\"$i\">".$months[$i-1]."\n";
print "<option value=\"$Existing_Item \">$Existing_Item</option>";
}
print "</select>";
print "<br>";
?>
<select size="5" name="user_choice" onclick="updateTextBox(this, currentSelections)">
<?php
foreach ($months as $Existing_Item)
{
//print "\t<option value=\"$i\">".$months[$i-1]."\n";
print "<option value=\"$Existing_Item \">$Existing_Item</option>";
}
print "</select>";
print "<br>";
?>
<textarea name = 'currentSelections' readonly="readonly" rows = "3" cols = "20"></textarea>
<br>
<?php
print "<input type='hidden' name='number' value=$number>";
print "<input type='hidden' name='menu_counter' value=$menu_counter>";
print "<input name=\"submit\" type=\"submit\" value=\"submit\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>";
}
//print "</form>";
else
{
// do whatever happens after the number of forms has been filled
print "<br>You choice are: <br>";
$InputDomain = $currentSelections;
$length = strlen($InputDomain);
$i = 0;
$counter = 1;
while($i < $length)
{
if ($InputDomain[$i] == "\n")
{
$ArrayOfDomain[] = trim($SelectedInputDomain);
$OrderNo[] = $counter;
$val1 = trim($SelectedInputDomain);
$val2 = $counter;
?>
<!--
<input type="hidden" name ="InputDomain[]" VALUE = "<?php echo $val1;?>">
<input type="hidden" name ="OrderNo[]" VALUE = "<?php echo $val2;?>">
-->
<?php
print "$val1 & $val2 <br>";
$counter++;
$SelectedInputDomain = NULL;
$i++;
}
else
{
$SelectedInputDomain = "$SelectedInputDomain" . "$InputDomain[$i]";
$i++;
}
}
}
}
?>
</body>
</html>
Is there anyone who has any suggestion regarding my problem? Thank you.
Phil Karras
08-12-2003, 10:09 PM
On my cs.yrex web site is a PHP program that displays all the form var inputs submitted along with an example of how to use it.
To use it simple replace your action with one like this:
HELP on Forms and posting values
http://www.jsworkshop.com/bb/viewtopic.php?p=2199#2199
<form action='http://cs.yrex.com/Hour9.php' method='POST'>
or
<form action='http://cs.yrex.com/Hour9.php' method='GET'>
I am haning problem storing the data after the submit button is pressed and it's in a loop. SO veral time submit button can be pressed and many items can be selected by this time. And after that loop I want to shoe the selected item. Please take a look of my valuable code and then suggest me what to do. Thank you. I have already quite lot of my time to learn the form and stuffs and there is no problem in my code, I guess.
Phil Karras
08-13-2003, 02:51 PM
Sorry, I do not know how to save data in PHP to a MySQL database.
Hope someone else can do that for you.
As to just saving data I have done that but I looked it up
in my example (Hour9.php), why not just download the example?
$flname = "data/Hour9Count.cnt";
$fp = fopen($flname, "r"); // Open to read current value
if(fp) { // Now, read the value
//print "<h1><font color='red'><b>Trying to open: $flname</b></font></h1><br><br>";
// Read value (one line) into $Cnt, Hour 10, but it says
fscanf($fp, "%d", $Cnt); // nothing about fscanf, that's C
++$Cnt;
print "<center><font face='arial' size='+1'>";
print "(This program has been used: $Cnt times.)";
print "</font></center><br>";
// Write new value to the file.
fclose($fp); // Close the file
$fp = fopen($flname, "w"); // Open to write current value
flock($fp, LOCK_SH);
fputs($fp, "$Cnt\n");
flock($fp, LOCK_UN);
fclose($fp); // Close the file
}
else { // Create an empty file now
print "<h1><font color='red'><b>Error, no file to open!</b></font></h1><br><br>";
}
fclose($fp); // Close the file
Thank you for oyur reply. I think you are going very different direction now. Here is my updatd code. Please take a look. My goal is to store all selected item in the an array and then display the array elemets in the quoted place at the bottom. Thank you.
<html>
<title>
Menu Test
</title>
<body>
<script type="text/javascript">
<!--
function updateTextBox(selectObj, textBoxObj)
{
var index = selectObj.selectedIndex;
var selection = selectObj.options[index].text;
textBoxObj.value += selection + "\n";
}
// -->
</script>
<?php
extract( $_GET );
if( !isset($submit))// do this if no GET vars
{
print "<form method=\"GET\">";
print "<p>Enter in the number of times below:</p>";
print "<input type=\"text\" name=\"number\" size=\"30\">";
$menu_counter = 0;
print "<input type='hidden' name='menu_counter' value=$menu_counter>";
print "<input name=\"submit\" type=\"submit\" value=\"send\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>" ;
}
else
{
if( $number>0 )
{
$months = array("January","February","March","April","May","June","July", "August","September","October","November","December");
$number = $HTTP_GET_VARS["number"]-1;
$menu_counter =$HTTP_GET_VARS["menu_counter"]+1;
print "<form method=\"GET\">";
print "Select components for term $menu_counter<br>";
?>
<select size="5" name="user_choice" onclick="updateTextBox(this, currentSelections)">
<?php
foreach ($months as $Existing_Item)
{
print "<option value=\"$Existing_Item \">$Existing_Item</option>";
}
print "</select>";
print "<br>";
?>
<select size="5" name="user_choice" onclick="updateTextBox(this, currentSelections)">
<?php
foreach ($months as $Existing_Item)
{
print "<option value=\"$Existing_Item \">$Existing_Item</option>";
}
print "</select>";
print "<br>";
?>
<textarea name = 'currentSelections' readonly="readonly" rows = "3" cols = "20"></textarea>
<br>
<?php
print "<input type='hidden' name='number' value=$number>";
print "<input type='hidden' name='menu_counter' value=$menu_counter>";
print "<input name=\"submit\" type=\"submit\" value=\"submit\">";
print "<input name=\"reset\" type=\"reset\" value=\"reset\">";
print "</form>";
}
else
{
// do whatever happens after the number of forms has been filled
// in this else statement I want have all seelected items from the menu
print "<br>You choice are: <br>";
$InputDomain = $currentSelections;
$length = strlen($InputDomain);
$i = 0;
$counter = 1;
while($i < $length)
{
if ($InputDomain[$i] == "\n")
{
$ArrayOfDomain[] = trim($SelectedInputDomain);
$OrderNo[] = $counter;
$val1 = trim($SelectedInputDomain);
$val2 = $counter;
print "$val1 & $val2 <br>";
$counter++;
$SelectedInputDomain = NULL;
$i++;
}
else
{
$SelectedInputDomain = "$SelectedInputDomain" . "$InputDomain[$i]";
$i++;
}
}
}
}
?>
</body>
</html>
Phil Karras
08-14-2003, 03:23 PM
Sorry, when I "store" something it usually means to a hard-disk, nonvolatile memory. Here's how to set up an array var:
var $table_array = array();
which you seem to know since you have one for your months. So, to load values into it you do this:
$table_array[0] = $menu_counter;
$table_array[1] = $Whatever;
where $menu_counter and $Whatever come from the HTML form, or your selected option value.
Here are the ways to get ALL the data from a form, it is in my example file Hour9.php, have you downloaded it yet? The other you might want to download is: Hour1-8.php
foreach($HTTP_POST_VARS as $key=>$value) {
print "<tr><td><b>$key</b></td><td>";
print"<font color='blue'><b>$value</b></font></td></tr>\n";
}
// and
foreach($HTTP_GET_VARS as $key=>$value) {
print "<tr><td><b>$key</b></td><td>";
print "<font color='blue'><b>$value</b></font></td></tr>\n";
}
Hope that helps.