Displaying the value from 2 dropdown lists

Reply

Join Date: Jan 2005
Posts: 10
Reputation: EPierre is an unknown quantity at this point 
Solved Threads: 0
EPierre EPierre is offline Offline
Newbie Poster

Displaying the value from 2 dropdown lists

 
0
  #1
Feb 1st, 2009
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, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,558
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 206
Sponsor
ardav's Avatar
ardav ardav is offline Offline
Anthrax Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #2
Feb 1st, 2009
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 4:39 am.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: EPierre is an unknown quantity at this point 
Solved Threads: 0
EPierre EPierre is offline Offline
Newbie Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #3
Feb 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,558
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 206
Sponsor
ardav's Avatar
ardav ardav is offline Offline
Anthrax Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #4
Feb 1st, 2009
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.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: EPierre is an unknown quantity at this point 
Solved Threads: 0
EPierre EPierre is offline Offline
Newbie Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #5
Feb 2nd, 2009
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, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,558
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 206
Sponsor
ardav's Avatar
ardav ardav is offline Offline
Anthrax Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #6
Feb 2nd, 2009
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:

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

  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:

  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:
  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 2:44 pm.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: EPierre is an unknown quantity at this point 
Solved Threads: 0
EPierre EPierre is offline Offline
Newbie Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #7
Feb 4th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: EPierre is an unknown quantity at this point 
Solved Threads: 0
EPierre EPierre is offline Offline
Newbie Poster

Re: Displaying the value from 2 dropdown lists

 
0
  #8
Apr 2nd, 2009
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:

  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, 1 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 858 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC