| | |
Displaying the value from 2 dropdown lists
![]() |
•
•
Join Date: Jan 2005
Posts: 10
Reputation:
Solved Threads: 0
How can the user obtain a specific result by choosing values from 2 dropdown list.
As a result, the value obtained can not be modified by the user.The table of ten rows by ten columns have to be stored in a mysql dbase.. It's certanly possible , but tedious and time-consuming by using a bunch of "if ... then statements".
I need some help, as I'm NULL in JavaScript, Ajax and PHP.
An illustration worthing 1000 words ...
From the matrix table, the final result is the coordinate of arow value and a column value.
Clear or confusing?
Hope someone can help....
Regards,
E. P.
As a result, the value obtained can not be modified by the user.The table of ten rows by ten columns have to be stored in a mysql dbase.. It's certanly possible , but tedious and time-consuming by using a bunch of "if ... then statements".
I need some help, as I'm NULL in JavaScript, Ajax and PHP.
An illustration worthing 1000 words ...
From the matrix table, the final result is the coordinate of arow value and a column value.
Clear or confusing?
Hope someone can help....
Regards,
E. P.
Sorry mate, my brain ain't too big. Can you clarify. How does the value in the table get created ?? They look like random numbers to me. Do you need a 10 x 10 or can you get away with a 1 x 100 [col x row].
Before asking for help again, I suggest you learn something about JS/Ajax/pHp, otherwise you won't understand any solutions presented to you. Loads of books/online tutorials available.
Before asking for help again, I suggest you learn something about JS/Ajax/pHp, otherwise you won't understand any solutions presented to you. Loads of books/online tutorials available.
Last edited by ardav; Feb 1st, 2009 at 4:39 am.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
•
•
Join Date: Jan 2005
Posts: 10
Reputation:
Solved Threads: 0
Tanks a lot for your prompt answer.
We set up an art website and the table is a kind of price list. So, all data are predetermined and not calculated. It's in fact a 10x10 table.
I exagerrate a bit when I tell I'm completely Null. I can read and understand a little bit a PHP or JS simple program. The fact is that I'm a newby and not really illiterate.
Do you need to see the actual table ?
Tanks again.
We set up an art website and the table is a kind of price list. So, all data are predetermined and not calculated. It's in fact a 10x10 table.
I exagerrate a bit when I tell I'm completely Null. I can read and understand a little bit a PHP or JS simple program. The fact is that I'm a newby and not really illiterate.
Do you need to see the actual table ?
Tanks again.
I see now. Due to the non-linear multiplication of figs X size, you can't use a simple calculator.
Your first dropdown (fig) will be a number (1 - 10)
Your second dropdown options should have a value equal to the field name of the option displayed.
I'm afraid, I'd use an Ajax solution for this so that users can see the cost before the submit/add to basket button was pressed:
In a javascript file (e.g. myAjax.js):
CREATE a newdbfunction.php file and insert into it:
In order to get this to work, you'll need the prototype.js file from www.prototypejs.org.
Include the javascript files thus:
Your first dropdown (fig) will be a number (1 - 10)
Your second dropdown options should have a value equal to the field name of the option displayed.
I'm afraid, I'd use an Ajax solution for this so that users can see the cost before the submit/add to basket button was pressed:
PHP Syntax (Toggle Plain Text)
<select id="fig" onchange="calc_price();return false;"> <option value = "" selected="selected">Select a fig</option> <option value = "1">1</option> <option value = "2">2</option> (etc) </select> <select id="dim" onchange="calc_price();return false;"> <option value = "" selected="selected">Select a dim</option> <option value = "field1">12”x16”/30x40 cm</option> <option value = "field2">16”x20”/40x50 cm</option> (etc) </select> <div id="price"></div>
In a javascript file (e.g. myAjax.js):
PHP Syntax (Toggle Plain Text)
function calc_price(){ if($F('dim') != "" || $F('fig')){ $('price').innerHTML = 'Not available'; } else{ var fig = $F('fig'); var dim = $F('dim'); var pars = "fig=" + fig + "&dim=" + dim; var oAjax = new Ajax.Updater('price','newdbfunction.php',{method: 'post',parameters: pars}); } }
CREATE a newdbfunction.php file and insert into it:
PHP Syntax (Toggle Plain Text)
(create a DBconnection string) $fieldname = $_POST['dim']; $num = $_POST['fig']; $result = mysql_query("SELECT {$fieldname} FROM pricetablename WHERE fig='{$num}'"); if(mysql_num_rows($result) > 0){ $data = mysql_fetch_array($result); if($data[$fieldname] == "-"){ echo "Not available"; }else{ echo "$" . $data[$fieldname]; } }else{ echo "Not available"; }
In order to get this to work, you'll need the prototype.js file from www.prototypejs.org.
Include the javascript files thus:
PHP Syntax (Toggle Plain Text)
<script src="/path/to/prototype.js" type="text/javascript"></script> <script src="/path/to/myAjax.js" type="text/javascript"></script>
Last edited by ardav; Feb 2nd, 2009 at 2:44 pm.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
•
•
Join Date: Jan 2005
Posts: 10
Reputation:
Solved Threads: 0
I come back to this problem since 2 days and create a dbase named price. At the end of command.html I put the submit button:
When sumit button is clicked I get an warning:
"mysqi-num_rows(): supplied argument is not a valid mysql resource in line 17" at newdbfunction.php.
Then, when I check the error with the code:
"$ ret = mysql-query($query) or dir(mysql_error());", the result is: [Price] Non available / mysql query is empty.
See the table price in attachment.
My question is: Why it does not "see" the table?
Help will be appreciated.
E. P.
PHP Syntax (Toggle Plain Text)
... <div id="price"></div> <input type="button" value="Submit" onClick="new Ajax.Updater('price','newdbfunction.php',{method: 'post'})";></input> </body>
When sumit button is clicked I get an warning:
"mysqi-num_rows(): supplied argument is not a valid mysql resource in line 17" at newdbfunction.php.
Then, when I check the error with the code:
"$ ret = mysql-query($query) or dir(mysql_error());", the result is: [Price] Non available / mysql query is empty.
See the table price in attachment.
My question is: Why it does not "see" the table?
Help will be appreciated.
E. P.
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: preg match help
- Next Thread: compile php binaries in windows for ftp_ssl_connect()
Views: 858 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache api archive array auto box buttons cakephp cart check checkbox class classes cms code combobox css curl database date development directory display download dropdown drupal dynamic echo email error file files form forms functions header href htaccess html image include insert integration ip java javascript joomla jquery limit link list login lookup loop mail menu methods mlm mod_rewrite multiple mysql onclick order parse password paypal php problem query radio recursion regex remote rows script search select server session sort source sql string structure syntax table update upload url user validate validation variable video web website wordpress xml






