PDA

View Full Version : How to store the data ?????


szms
Tue 12th Aug '03, 11:31am
I am 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>

qxh
Tue 12th Aug '03, 11:34am
There is no need in creating a new thread everytime you've made an adjustment to your script. I've done a quick count and can see 8 threads about this, and I'm sure there are more on other pages. Also put your PHP inside [*php][*/php] tags. (Remove the *'s)

szms
Tue 12th Aug '03, 11:36am
I ma new in web programming as well as posting the problems. By the way can you help me to solve this problem?

qxh
Tue 12th Aug '03, 11:40am
I'll try and help soon, I'm just about to pop out now though. But yeah, in future you don't need to keep creating new threads, simply reply to the one you've already made.

szms
Tue 12th Aug '03, 11:19pm
Is there anyone who have some suggestion regarding my problem? Thank you.

qxh
Wed 13th Aug '03, 6:18am
Just putting it in some PHP tags so it's easier to read, then I'll take a look:


<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>

szms
Wed 13th Aug '03, 2:06pm
Well, any help regarding my problem will be appriciated. Thank you.

qxh
Wed 13th Aug '03, 2:41pm
Mate, as I've said before bumping your topics will not result in a faster response.

Chroder
Wed 13th Aug '03, 2:45pm
I'm not ginna struggle to read it with no tabs :eek:

szms
Wed 13th Aug '03, 2:59pm
Well now you can take a lok of my nice looking code...!! Please help me to solve the problem.



<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

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>