943,841 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 990
  • PHP RSS
Feb 1st, 2009
0

Displaying the value from 2 dropdown lists

Expand Post »
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.
Attached Files
File Type: pdf Table_1.pdf (7.0 KB, 5 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EPierre is offline Offline
16 posts
since Jan 2005
Feb 1st, 2009
0

Re: Displaying the value from 2 dropdown lists

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.
Last edited by ardav; Feb 1st, 2009 at 5:39 am.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,691 posts
since Oct 2006
Feb 1st, 2009
0

Re: Displaying the value from 2 dropdown lists

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EPierre is offline Offline
16 posts
since Jan 2005
Feb 1st, 2009
0

Re: Displaying the value from 2 dropdown lists

I saw your pdf, but I don't get your rationale. Is a art piece (say no. 3) linked to table item '1C'? It looks like a non-standard method of linking items.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,691 posts
since Oct 2006
Feb 2nd, 2009
0

Re: Displaying the value from 2 dropdown lists

If you don't follow my rationale, it's certainly because I was not clear enough and the title of my post is confusing

Let me try again.
See an attached pdf with full explanation and graphics.

I appreciate the time you devote to my issue.

E. P.
Attached Files
File Type: pdf Price list on dropdown.pdf (18.5 KB, 6 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EPierre is offline Offline
16 posts
since Jan 2005
Feb 2nd, 2009
0

Re: Displaying the value from 2 dropdown lists

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:

PHP Syntax (Toggle Plain Text)
  1. <select id="fig" onchange="calc_price();return false;">
  2. <option value = "" selected="selected">Select a fig</option>
  3. <option value = "1">1</option>
  4. <option value = "2">2</option>
  5. (etc)
  6. </select>
  7.  
  8. <select id="dim" onchange="calc_price();return false;">
  9. <option value = "" selected="selected">Select a dim</option>
  10. <option value = "field1">12”x16”/30x40 cm</option>
  11. <option value = "field2">16”x20”/40x50 cm</option>
  12. (etc)
  13. </select>
  14.  
  15. <div id="price"></div>

In a javascript file (e.g. myAjax.js):

PHP Syntax (Toggle Plain Text)
  1. function calc_price(){
  2. if($F('dim') != "" || $F('fig')){
  3. $('price').innerHTML = 'Not available';
  4. } else{
  5. var fig = $F('fig');
  6. var dim = $F('dim');
  7. var pars = "fig=" + fig + "&dim=" + dim;
  8. var oAjax = new Ajax.Updater('price','newdbfunction.php',{method: 'post',parameters: pars});
  9. }
  10. }

CREATE a newdbfunction.php file and insert into it:

PHP Syntax (Toggle Plain Text)
  1. (create a DBconnection string)
  2.  
  3. $fieldname = $_POST['dim'];
  4. $num = $_POST['fig'];
  5.  
  6. $result = mysql_query("SELECT {$fieldname} FROM pricetablename WHERE fig='{$num}'");
  7.  
  8. if(mysql_num_rows($result) > 0){
  9. $data = mysql_fetch_array($result);
  10. if($data[$fieldname] == "-"){
  11. echo "Not available";
  12. }else{
  13. echo "$" . $data[$fieldname];
  14. }
  15.  
  16. }else{
  17. echo "Not available";
  18. }


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)
  1. <script src="/path/to/prototype.js" type="text/javascript"></script>
  2. <script src="/path/to/myAjax.js" type="text/javascript"></script>
Last edited by ardav; Feb 2nd, 2009 at 3:44 pm.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,691 posts
since Oct 2006
Feb 4th, 2009
0

Re: Displaying the value from 2 dropdown lists

Tanks a lot for your help.
I quick look at the solution. As I have an emergency now, I'll examine it more seriously later.

Regards, E. P.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EPierre is offline Offline
16 posts
since Jan 2005
Apr 2nd, 2009
0

Re: Displaying the value from 2 dropdown lists

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:

PHP Syntax (Toggle Plain Text)
  1. ...
  2. <div id="price"></div>
  3. <input type="button" value="Submit" onClick="new Ajax.Updater('price','newdbfunction.php',{method: 'post'})";></input>
  4. </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.
Attached Files
File Type: pdf price.sql.pdf (10.3 KB, 3 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EPierre is offline Offline
16 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: preg match help
Next Thread in PHP Forum Timeline: compile php binaries in windows for ftp_ssl_connect()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC