根据所选的下拉列表创建字母数字ID

时间:2017-06-23 05:10:04

标签: php mysql

我有HTML表单,其中包含一个名为Type的下拉名称,包含Request,Complaint,Query等值。 如果我们选择type作为Request,那么DB中的ID应该是REQ1,如果选择Complaint则是COMP1,如果是Query,那么QUE1和ID应该按类型递增。

import GoogleMaps
import GooglePlaces

    class SrarchPlacesViewController: UIViewController, UISearchDisplayDelegate,UISearchBarDelegate {

        @IBOutlet weak var searchView: UISearchBar!
        var searchBar: UISearchBar?
        var tableDataSource: GMSAutocompleteTableDataSource?
        var srchDisplayController: UISearchDisplayController?
        var resultsViewController: GMSAutocompleteResultsViewController?
        var searchController: UISearchController?

     override func viewDidLoad() {
            super.viewDidLoad()
            searchView.delegate = self
            searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 250.0, height: 44.0))

            tableDataSource = GMSAutocompleteTableDataSource()
            tableDataSource?.delegate = self


            srchDisplayController = UISearchDisplayController(searchBar: searchView, contentsController: self)
            srchDisplayController?.searchResultsDataSource = tableDataSource
            srchDisplayController?.searchResultsDelegate = tableDataSource

            srchDisplayController?.delegate = self


        }
       @objc(didUpdateAutocompletePredictionsForTableDataSource:) func didUpdateAutocompletePredictions(for tableDataSource: GMSAutocompleteTableDataSource) {
        // Turn the network activity indicator off.
        UIApplication.shared.isNetworkActivityIndicatorVisible = false
        // Reload table data.
        srchDisplayController?.searchResultsTableView.reloadData()
    }

    @objc(didRequestAutocompletePredictionsForTableDataSource:) func didRequestAutocompletePredictions(for tableDataSource: GMSAutocompleteTableDataSource) {
        // Turn the network activity indicator on.
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
        // Reload table data.
        srchDisplayController?.searchResultsTableView.reloadData()
    }

    //MARK:- SEARCH BAR FUCNTION

    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
        // self.tableViews.hidden = true
        dPrint("BIGIN")
    }

    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
        // self.tableViews.hidden = false
        dPrint("ending")

    }

    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        // self.tableViews.hidden = false
        dPrint("cancel")
    }



    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        if(searchText == ""){
            dPrint("text chnange")
            // self.tableViews.hidden = false
        }

    }

    @objc(tableDataSource:didSelectPrediction:) func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didSelect prediction: GMSAutocompletePrediction) -> Bool {
        return true
    }


    }
    extension SrarchPlacesViewController: GMSAutocompleteTableDataSourceDelegate{
        /**
         * Called when a non-retryable error occurred when retrieving autocomplete predictions or place
         * details. A non-retryable error is defined as one that is unlikely to be fixed by immediately
         * retrying the operation.
         * <p>
         * Only the following values of |GMSPlacesErrorCode| are retryable:
         * <ul>
         * <li>kGMSPlacesNetworkError
         * <li>kGMSPlacesServerError
         * <li>kGMSPlacesInternalError
         * </ul>
         * All other error codes are non-retryable.
         * @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
         * @param error The |NSError| that was returned.
         */
        public func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didFailAutocompleteWithError error: Error) {
            dPrint("Error: \(error.localizedDescription)")
        }

        func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didAutocompleteWith place: GMSPlace) {
            srchDisplayController?.isActive = false

            // Do something with the selected place.
           print(place.coordinate)

            print("Place name: \(place.name)")
            print("Place address: \(place.formattedAddress)")
            print("Place attributions: \(place.attributions)")
        }

        @objc(searchDisplayController:shouldReloadTableForSearchString:) func searchDisplayController(_ controller: UISearchDisplayController, shouldReloadTableForSearch searchString: String?) -> Bool {
            tableDataSource?.sourceTextHasChanged(searchString)
            return false
        }


    }

在上面的代码中我们从drop -down中选择票证类型。这里我想区分票证的ID,就像投诉或请求或查询一样。 如果Ticket类型是投诉,则该票证ID与Prefix COMP一样保存,如果Query则为QUE,如果请求则为REQ。

表格如下所示。

ID | TITLE

REQ1 | TITLE1

REQ2 |标题2

REQ3 |标题2

COMP1 | TITLE3

1 个答案:

答案 0 :(得分:0)

这个将有用

您的第一个文件代码

添加最新的.js文件
链接:letest .js library download

<强> select.php

<form method="post" action="select1.php">
<select name="select">
    <?php
        $select=array(0=>"select",1=>"Request",2=>"Complaint",3=>"Query");
        for($id=0;$id<=3;$id++)
        {
            ?>
                <option value="<?php echo $id; ?>"><?php echo $select[$id]; ?></option>
            <?php
        }
    ?>
</select>
<input type="hidden" name="name" id="name">
<input type="submit" name="">
</form>

<script type="text/javascript" src="../library/q.js"></script>
<script type="text/javascript">
    $(this).change(function(){
        if($('select').val()!=0)
            $('#name').val($('select :selected').text());
        else
            $('#name').val("");
    });
</script>

您的第二个文件代码

<强> select1.php

<?php
    if(isset($_POST['select']) && !empty($_POST['select']))
    {
        $id=$_POST['select'];
        $name=$_POST['name'];
        $name=strtoUpper(substr($name,0,3));
        echo $name.$id;
    }else
    {
        header("location:select.php");
    }
?>