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.

Recommended Answers

All 7 Replies

Member Avatar for diafol

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.

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.

Member Avatar for diafol

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.

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.

Member Avatar for diafol

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:

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

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:

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

<script src="/path/to/prototype.js" type="text/javascript"></script>
<script src="/path/to/myAjax.js" type="text/javascript"></script>

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.

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:

...
<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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.