简体   繁体   English

mysql的下拉列表的值

[英]value of dropdown list from mysql

I'm trying to compose an estimate formula, and I stucked with value of dropdown list populated by MySQL. 我试图组成一个估计公式,并且坚持使用MySQL填充的下拉列表的值。

The idea of this formula is when a user select a service from dropdown list and put the quantity in textfield the program will compute the price for the service. 此公式的想法是,当用户从下拉列表中选择一项服务并将数量输入文本字段时,程序将计算该服务的价格。

The value of the prize is selected from MySQL table. 从MySQL表中选择奖品的值。

$query="SELECT $con_tent FROM services WHERE $id;
$con_tent= 'price'. '*'. $qunatity

But I don't know how to get the value from dropdwon list. 但是我不知道如何从dropdwon列表中获取价值。

Probably with Ajax but still don't know how. 可能与Ajax合作,但仍然不知道如何做。

I solved this by modyfing code from http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html 我通过修改http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html中的代码来解决此问题

<?php
    require_once 'login.php';
    $db_server = mysql_connect($db_hostname, $db_user, $db_password);
    mysql_select_db($db_database) or die("unable to select database:" . mysql_error());

    echo "<form action=licz.php method='post'>";
    echo " <label for=\"select\"><select name=\"\" value=\"Select\" size=\"1\">";

    $query = "SELECT * FROM uslugi ORDER BY id ASC";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) {
        global $ff;

        $ajdi = $row['id'];

        $nazwa = $row['nazwa'];
        $options.= "<option value=\"$ajdi\" name=\"oko\">" . $nazwa . $ajdi;
    }
    echo "<option>";
    echo $options;

    echo "</option></select>";
    echo "  <input type=\"submit\" name=\"Submit\" value=\"Submit\">";

    echo "</form>";
    function wybor() {
        global $id;
        global $con_tent;
        $var = 'price' . '*';
        $quantity = 3;
         //quantity will by from textfield but now it constant
        $id_value = 1;
         // here i need to make it dynamic
        $id = "id={$id_value}";
        $con_tent = $var . $quantity;
    }

    echo wybor();

    $query = "SELECT $con_tent FROM services WHERE $id";
     //query

    if (!$query) Die("Unable to query: " . mysql_error());

    $result = mysql_query($query);

    if (!$result) Die("Unable to query: " . mysql_error());
    $rows = mysql_num_rows($result);
    for ($a = 0; $a < $rows; ++$a) {
        $row = mysql_fetch_row($result);

        echo $row[0] . " ";
        echo $row[1] . " ";
        echo $row[2] . " ";
        echo $row[3] . "$br";
    }


?>

You should apply ajax call to get value for database when there is a change in select box through calling a function on onchange event of javascript. 当选择框发生更改时,应通过对javascript的onchange事件调用函数来应用ajax调用以获取数据库的值。

Read More for jquery AJAX 阅读有关jquery AJAX的更多信息

http://www.sitepoint.com/ajax-jquery/ http://www.sitepoint.com/ajax-jquery/

http://www.tutorialspoint.com/jquery/jquery-ajax.htm http://www.tutorialspoint.com/jquery/jquery-ajax.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM