By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,825 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,825 IT Pros & Developers. It's quick & easy.

help on coding needed

keyvanrahmadi
P: 57
Hello everyone,

i am a bit coonfused and possibly being completely dense about the solution for the following dilema:

I have created 6 drop down menus which are being populated with data:
[php]
<?php
$heading = 'ADMIN PAGE';
echo "<u><h1><center>$heading</center></h1></u>\n";
$queries = array(
array('text' => "Location",
'query' => "SELECT * FROM location_o2",
'selname' => "location"),
array('text' => "Select Car",
'query' => "SELECT * FROM make_o2",
'selname' => "make"),
array('text' => "Select Class",
'query' => "SELECT * FROM class_o2",
'selname' => "class"),
array('text' => "Select colour",
'query' => "SELECT * FROM colour_o2",
'selname' => "colour"),
array('text' =>"Fuel Type",
'query' =>"SELECT * FROM fuel_o2",
'selname'=>"FUEL"),
array('text' => "Transmission Type",
'query' =>"SELECT * FROM transmission_o2",
'selname' =>"Transmission")
);
mysql_connect("server", "user", "password") or die(mysql_error());
mysql_select_db("kahma02db") or die(mysql_error());

//loop through $SQL array, select data and make dropdown list.

for ($i=0; $i < count($queries); $i++) {
echo "<label style='width:90px;'>{$queries[$i]['text']}</label><select style='width:150px;' name='" . $queries[$i]['selname'] . "'>";
$retid = mysql_query($queries[$i]['query']);

while ($row = mysql_fetch_array($retid)) {

/* display menu items */
echo "<OPTION VALUE='{$row[0]}'>{$row[1]}</OPTION>";
// End WHILE

}
echo '</select><br />';
}
?>
<br />
<br />
Collection Date:
<select name="Day">
<optgroup label="Day">
<?php
for ($i=1; $i <= 31; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>
<select name="month">
<optgroup label="Month">
<?php
for ($i=1; $i <= 12; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>
<select name="year">
<optgroup label="Year">
<?php
for ($i=2007; $i <= 2010; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>

Return Date:
<select name="Day">
<optgroup label="Day">
<?php
for ($i=1; $i <= 31; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>
<select name="month">
<optgroup label="Month">
<?php
for ($i=1; $i <= 12; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>
<select name="year">
<optgroup label="Year">

<?PHP
for ($i=2007; $i <= 2010; $i++)
{
echo "<option value=\"$i\">$i</option>";
}
?>
</optgroup>
</select>
[/php]
The whole idea is that the user selects his/her choices from different drop down menus and submits the choice, which in return will create an order form on the same page populated with the users choice. The last part is what i have no idea how to do. If any one can lend me a hand here or point me at the right direction with hints i be very gratefull.

thanks in adavnce

Keyvan

Read the Posting Guidelines before you post in this forum! - moderator
Feb 7 '07 #1
Share this Question
Share on Google+
7 Replies


Atli
Expert 5K+
P: 5,058
Hi.

Im a bit confused here. (bit more than usual I mean ofc :P)

You have created 6 dropdown boxes, filled with data, and you need to put the selected data into another form?

Why cant you just send the data directly from the dropdown boxes to wherever you want it to go?

btw you should put the code you post in [ code] .. [ /code] thingie
Feb 7 '07 #2

keyvanrahmadi
P: 57
Hi.

Im a bit confused here. (bit more than usual I mean ofc :P)

You have created 6 dropdown boxes, filled with data, and you need to put the selected data into another form?

Why cant you just send the data directly from the dropdown boxes to wherever you want it to go?

btw you should put the code you post in [ code] .. [ /code] thingie
My apologies for missing the [code] tage, was wondering why it didnt look right when i posted it, but now i know i will use it for my later posts.

To answer your question why cant i send it directly, i have to say i cant see any reason why not, but again i dont know how to do that either. what i was trying to achieve was a page that customer who are trying to hire a car for certain lenght of time to goto, chose the type of car, how long they want it for, fill the order form and place the order.

The PHP code from my original post, creates the boxes with data being read from my mysql database i have designed. The database has all the information regarding different car models, transmission, fuel type etc....

So i suppose what i am looking for is hints and advise on how i can achieve this.

Hope this clears the original post a bit and would appriciate all help and hints you can throw my way.

keyvan
Feb 7 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
Maybe I am missing something, but where is the <form> in which the select boxes are created and that is submitted by the user? And where is the code for handling this submit request?

Ronald :cool:
Feb 7 '07 #4

keyvanrahmadi
P: 57
Maybe I am missing something, but where is the <form> in which the select boxes are created and that is submitted by the user? And where is the code for handling this submit request?

Ronald :cool:
Hmmm ok i have not created a form as yet, which is the part i have a problem with.

I have created the drop downs, each reading directly the information from my database. what i was trying to achieve was to for users to go through each drop down and chose the appropriate data and then submit the chosen fields into a form. I am not how ever sure how to create the form which reads the users selections from drop down menus.

I am really sorry if this is not making sense and i hope i have explained it better now.
Feb 7 '07 #5

Atli
Expert 5K+
P: 5,058
This is a code that creates a form with a couple of drop down boxes and processes the data when it is sent.

Though it might help with your problem.

[PHP]<?php

// Check if the data has been posted
if(isset($_POST['FormSubmit']))
{
// Print the selected options
echo "\r\n<br />Selected options:";
echo "\r\n<br />&nbsp;Box1: ". $_POST['Box1'];
echo "\r\n<br />&nbsp;Box2: ". $_POST['Box2'];
}
// Print the form
else
{
// Create a list of dropdown boxes and their options
$boxes = array
(
array
(
'Name' => 'Box1',
'Options' => array
(
array('Text' => 'Option 1', 'Value' => '1'),
array('Text' => 'Option 2', 'Value' => '2'),
array('Text' => 'Option 3', 'Value' => '3')
)
),

array
(
'Name' => 'Box2',
'Options' => array
(
array('Text' => 'Option 1', 'Value' => '1'),
array('Text' => 'Option 2', 'Value' => '2'),
array('Text' => 'Option 3', 'Value' => '3')
)
)
);

// Open form
echo "\r\n".'<form action"" method="post">';

// Print all dropdown boxes
foreach($boxes as $box)
{
echo "\r\n".'<p><select name="'. $box['Name'] .'">';

// Print all options for the dropdown box
foreach($box['Options'] as $option)
{
echo "\r\n\t".'<option value="'. $option['Value'] .'">'. $option['Text'] .'</option>';
}

echo "\r\n".'</select></p>';
}

// Print submit button and close form
echo "\r\n".'<br /><input type="submit" name="FormSubmit" value="Submit" />';
echo "\r\n".'</form>';
}
?>[/PHP]
Feb 7 '07 #6

keyvanrahmadi
P: 57
I am sorry, i have been away and not had time, to try the code and i also wanted to thank you for the help :) its greatly appriciated.

I let you know how it's my progress going when i get back home.


Thanks once again

keyvan
Feb 9 '07 #7

keyvanrahmadi
P: 57
This is a code that creates a form with a couple of drop down boxes and processes the data when it is sent.

Though it might help with your problem.

[PHP]<?php

// Check if the data has been posted
if(isset($_POST['FormSubmit']))
{
// Print the selected options
echo "\r\n<br />Selected options:";
echo "\r\n<br />&nbsp;Box1: ". $_POST['Box1'];
echo "\r\n<br />&nbsp;Box2: ". $_POST['Box2'];
}
// Print the form
else
{
// Create a list of dropdown boxes and their options
$boxes = array
(
array
(
'Name' => 'Box1',
'Options' => array
(
array('Text' => 'Option 1', 'Value' => '1'),
array('Text' => 'Option 2', 'Value' => '2'),
array('Text' => 'Option 3', 'Value' => '3')
)
),

array
(
'Name' => 'Box2',
'Options' => array
(
array('Text' => 'Option 1', 'Value' => '1'),
array('Text' => 'Option 2', 'Value' => '2'),
array('Text' => 'Option 3', 'Value' => '3')
)
)
);

// Open form
echo "\r\n".'<form action"" method="post">';

// Print all dropdown boxes
foreach($boxes as $box)
{
echo "\r\n".'<p><select name="'. $box['Name'] .'">';

// Print all options for the dropdown box
foreach($box['Options'] as $option)
{
echo "\r\n\t".'<option value="'. $option['Value'] .'">'. $option['Text'] .'</option>';
}

echo "\r\n".'</select></p>';
}

// Print submit button and close form
echo "\r\n".'<br /><input type="submit" name="FormSubmit" value="Submit" />';
echo "\r\n".'</form>';
}
?>[/PHP]
Now i have had time to digest the information on the code, i have a quick question:

It seems that the information on the drop down boxes need to be hard coded, how can i add sql quary to this, so i dont have to hard code the whole data i have?

thax once again for any help.

keyvan
Feb 12 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.