andybid
11-30-2010, 12:30 PM
Hi
I am trying to streamline my signup process.
Where I am.
user selects no of services 1-5
this is passed to a select.php dynamically which includes 1res.php if input=1 2res.php if input=2 etc.
This loads a page with no of fields to be completed
first drop box = months (dynamic load from db)
second box = weeks (dynamic load from db where = months input)
third box = cost (dynamic but not what wanted)
what I need
the first and second boxs work ok
when the user selects a value in the second box, I want to return a cost value by running a SELECT cost FROM resolutions.cost WHERE months='months input' AND weeks = 'weeks input'
this has to return a value for each row of inputs, ie 1 res.php has 1 row, 2.res.php= 2 row etc.
also when the cost fields are updated, if all rows cost have a value ( so not "") a total cost field is returned at the bottom of the page.
I am stuck where I am now. I have tried various versions of code and changing things over the last 4 days and can not get the result I need. I am doing something wrong. In order to save my marriage with the time I spendin on this, I need some help.
For some reason I cant even get the sql query to return the cost based on weeks value and months value?????!!!!!
Can anyone help me sort this.
To keep things simple, I have included the code for one field(1res.php)
you can see the code below at http://madandi.gotdns.com
Thanks
1res.php
<?php
include('connections/resdb.php');
include('func.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User input 1 field (1res.php)</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "drop_1",
drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax_tier_three(id, response) {
$('#wait_2').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
</head>
<body>
<p>
<form id="FormRes1" action="" method="post">
<select name="drop_1" id="drop_1">
<option value="" selected="selected" disabled="disabled">Select a Category</option>
<?php getTierOne(); ?>
</select>
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_1" style="display: none;"></span>
<span id="wait_2" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_2" style="display: none;"></span>
</form>
</p>
<p>
<?php if(isset($_POST['submit'])){
$drop = $_POST['drop_1'];
$drop_2 = $_POST['drop_2'];
$drop_3 = $_POST['drop_3'];
echo "You selected a ";
echo $drop_3." ".$drop." ".$drop_2;
}
$result = mysql_query("select cost from resolutions.cost where months='$drop' and weeks='$drop_2'") or die (mysql_error());
while($fee_1 = mysql_fetch_array( $result ))
echo $fee_1."---- $fee_1 value ---".$result."-- $result value --".$drop_3." --- drop_3 value";
?>
</body>
</html>
func.php
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT months FROM resolutions.cost")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['months'].'">'.$tier['months'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('connections/resdb.php');
$result = mysql_query("SELECT weeks FROM resolutions.cost WHERE months='$drop_var'")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['weeks'].'">'.$drop_2['weeks'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
include_once('connections/resdb.php');
$result = mysql_query("SELECT cost FROM resolutions.cost WHERE weeks='$drop_var'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['cost'].'">'.$drop_3['cost'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_3').hide();
$('#drop_3').change(function(){
$('#wait_3').show();
$('#result_3').hide();
$.get(\"func.php\", {
func: \"drop_3\",months: $('#drop_1')
drop_var: $('#drop_3').val()
}, function(response){
$('#result_3').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
echo '<input type="submit" name="submit" value="Submit" />';
}
?>
I am trying to streamline my signup process.
Where I am.
user selects no of services 1-5
this is passed to a select.php dynamically which includes 1res.php if input=1 2res.php if input=2 etc.
This loads a page with no of fields to be completed
first drop box = months (dynamic load from db)
second box = weeks (dynamic load from db where = months input)
third box = cost (dynamic but not what wanted)
what I need
the first and second boxs work ok
when the user selects a value in the second box, I want to return a cost value by running a SELECT cost FROM resolutions.cost WHERE months='months input' AND weeks = 'weeks input'
this has to return a value for each row of inputs, ie 1 res.php has 1 row, 2.res.php= 2 row etc.
also when the cost fields are updated, if all rows cost have a value ( so not "") a total cost field is returned at the bottom of the page.
I am stuck where I am now. I have tried various versions of code and changing things over the last 4 days and can not get the result I need. I am doing something wrong. In order to save my marriage with the time I spendin on this, I need some help.
For some reason I cant even get the sql query to return the cost based on weeks value and months value?????!!!!!
Can anyone help me sort this.
To keep things simple, I have included the code for one field(1res.php)
you can see the code below at http://madandi.gotdns.com
Thanks
1res.php
<?php
include('connections/resdb.php');
include('func.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User input 1 field (1res.php)</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "drop_1",
drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
function finishAjax_tier_three(id, response) {
$('#wait_2').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
</head>
<body>
<p>
<form id="FormRes1" action="" method="post">
<select name="drop_1" id="drop_1">
<option value="" selected="selected" disabled="disabled">Select a Category</option>
<?php getTierOne(); ?>
</select>
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_1" style="display: none;"></span>
<span id="wait_2" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_2" style="display: none;"></span>
</form>
</p>
<p>
<?php if(isset($_POST['submit'])){
$drop = $_POST['drop_1'];
$drop_2 = $_POST['drop_2'];
$drop_3 = $_POST['drop_3'];
echo "You selected a ";
echo $drop_3." ".$drop." ".$drop_2;
}
$result = mysql_query("select cost from resolutions.cost where months='$drop' and weeks='$drop_2'") or die (mysql_error());
while($fee_1 = mysql_fetch_array( $result ))
echo $fee_1."---- $fee_1 value ---".$result."-- $result value --".$drop_3." --- drop_3 value";
?>
</body>
</html>
func.php
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT months FROM resolutions.cost")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['months'].'">'.$tier['months'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('connections/resdb.php');
$result = mysql_query("SELECT weeks FROM resolutions.cost WHERE months='$drop_var'")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['weeks'].'">'.$drop_2['weeks'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
include_once('connections/resdb.php');
$result = mysql_query("SELECT cost FROM resolutions.cost WHERE weeks='$drop_var'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['cost'].'">'.$drop_3['cost'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_3').hide();
$('#drop_3').change(function(){
$('#wait_3').show();
$('#result_3').hide();
$.get(\"func.php\", {
func: \"drop_3\",months: $('#drop_1')
drop_var: $('#drop_3').val()
}, function(response){
$('#result_3').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
echo '<input type="submit" name="submit" value="Submit" />';
}
?>