Display Search Results in Modal Dialog/Box

岁酱吖の 提交于 2021-01-28 07:37:13

问题


I can't seem to get my modal box to display the results of a search, I can submit the form and the modal box will appear, I've tried echoing my variables in the modal box but nothing shows. I've tried putting the Search script, and script in the modal box. Nothing. I've tried it with almost every Modal box I could find, so it's not the modal boxes I'm just not doing something right. I just know I'm tired, my eyes hurt, and I'm just about to give up doing this. I just don't want the page to refresh when searching, because it clears all the values the user in puts to search for a model id. In order to create a creature, you must have the model ID which aren't easy to find I'm trying to provide my copy of the model ids to be searched through. Please. Any help is appreciated, thanks.

THE FORM

// My form
    <form name="Form2" method="get" action="" enctype="application/x-www-form-urlencoded" id="Form2">
    <input type="text" id="Editbox19" style="position:absolute;left:20px;top:80px;width:191px;height:35px;line-height:35px;z-index:0;" name="name" value="" class"rounded">
    <div id="wb_Text25" style="position:absolute;left:20px;top:134px;width:58px;height:34px;z-index:1;text-align:left;">
    <span style="color:#FFFFFF;font-family:Arial;font-size:15px;">Entry ID:</span></div>
    <input type="text" id="Editbox20" style="position:absolute;left:20px;top:153px;width:191px;height:35px;line-height:35px;z-index:2;" name="entry" value=""class"rounded">
    <div id="wb_Image2" style="position:absolute;left:10px;top:5px;width:221px;height:31px;z-index:3;">
    <img src="images/modelid.png" id="Image2" alt=""></div>
    <div id="wb_Text24" style="position:absolute;left:18px;top:46px;width:227px;height:34px;z-index:4;text-align:left;">
    <span style="color:#FFFFFF;font-family:Arial;font-size:15px;"><br> Name:</span></div>

    <input type="submit" id="Button1" onclick="$('#jQueryDialog1').dialog('open');return false;" name="" value="Submit" style="position:absolute;left:269px;top:187px;width:96px;height:25px;z-index:2;">// What activates the Modal Box

    </form>

The Modal Box

//Modal Box itself
<div id="jQueryDialog1" style="z-index:3;" title="This is the title">
//Modal Box Content where I want to display Search results.
</div>
</div>

My Script:

 // Modal Box Script
    <script>
    $(document).ready(function()
    {
       var jQueryDialog1Opts =
       {
          width: 554,
          height: 367,
          position: { my: 'center', at: 'center', of: window },
          resizable: true,
          draggable: true,
          closeOnEscape: true,
          autoOpen: false
       };
       $("#jQueryDialog1").dialog(jQueryDialog1Opts);
    });
    </script>

My Search Script:

  <?php 
        if(isset($_GET['name'], $_GET['entry'])) {
        try { 

        $host = "xxxxxx";
        $user = "xxxxxxxx";
        $password = "xxxxxx";
        $database_name = "xxxxxxxx";
        $dbh = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
        //PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ));

        $conditions = array();
        $oemSearch = $_GET['name'];
        $oempnSearch = $_GET['entry'];
        $min = 1;
        $oemLen = strlen($oemSearch);
        $oempnLen = strlen($oempnSearch);

        if ($oemSearch == "" && $oempnSearch == "") {
         echo "You must enter a Name or Entry ID";
         exit;
        }
         if ($oemSearch != "" && $oemLen < $min) { 
         echo "You must enter an Entry ID of atleast 1 Character.";
         exit;
        }
         if ($oempnSearch != "" && $oempnLen < $min) { 
         echo "You must enter at least 3 P/N characters.";
         exit;
        }
        if ($oemSearch != "" && $oempnSearch == "") {
        $stmt = $dbh->prepare("select * from creature_template WHERE name LIKE '%$oemSearch%' ORDER BY entry LIMIT :limit OFFSET :offset");
        //$query->bindValue(1, "%$oemSearch%", PDO::PARAM_STR);
        }
        if ($oemSearch == "" && $oempnSearch != "") {
        $stmt = $dbh->prepare("select * from creature_template WHERE name LIKE '%$oempnSearch%' ORDER BY entry LIMIT :limit OFFSET :offset");
        //$query->bindValue(1, "%$oemSearch%", PDO::PARAM_STR);
        }
        if ($oemSearch != "" && $oempnSearch != "") {
        $stmt = $dbh->prepare("select * from creature_template WHERE name LIKE '%$oemSearch%' OR entry LIKE '%$oempnSearch%' ORDER BY entry LIMIT :limit OFFSET :offset");
        //$query->bindValue(1, "%$oemSearch%", PDO::PARAM_STR);
        }

        // Find out how many items are in the table
        $total = $dbh->query("SELECT COUNT(*) AS num FROM creature_template ")->fetchColumn();

        // How many items to list per page
        $limit = 10;

        // How many pages will there be
        $pages = ceil($total / $limit);

        // What page are we currently on?
        $page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
            'options' => array(
            'default'   => 1,
            'min_range' => 1,
            ),
        )));

        // Calculate the offset for the query
        $offset = ($page - 1) * $limit;

        // Some information to display to the user
        $start = $offset + 1;
        $end = min(($offset + $limit), $total);

        // Bind the query params
        $stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
        $stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
        $stmt->execute();

        // Do we have any results?
        if ($stmt->rowCount() > 0) {
            // Define how we want to fetch the results
            $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $iterator = new IteratorIterator($stmt);

           // Display the results
        echo "<table class='views-table' border=1>";   
              echo "<tr class='tblheader'><th bgcolor=#00CC00>Name</th><th bgcolor=#00CC00>Entry ID</th><th bgcolor=#00CC00>Model ID</th></tr>";
            foreach ($iterator as $row) {
              echo "<tr class=odd views-row-first1><td><a href=http://wowhead.com/npc=";         
                echo $row['entry'];
                echo "></td><td><b>";
                echo $row['entry'];
                echo "</a></td><td><b>";
                echo $row['modelid1'];
                echo "</td></tr></b>";
            }
             echo "</table>"; 


        } else {
            echo '<p>No results could be displayed.</p>';
        }

        } catch (Exception $e) {
            echo '<p>', $e->getMessage(), '</p>';
        }}
        ?>

回答1:


Are you using ajax at all? Remove your onclick from your button and try:

    $("#Button1").click(function(){
    var name = document.getElementById("Editbox19"); 
    var entry = document.getElementById("Editbox20"); 
    var jQueryDialog1Opts =
    {
    width: 554,
    height: 367,
    position: { my: 'center', at: 'center', of: window },
    resizable: true,
    draggable: true,
    closeOnEscape: true,
    autoOpen: false
    };

        $.ajax({
            url: "search.php?name="+name+"&entry="+entry,
            type: "GET",
            success:function(data){
                    $("#jQueryDialog1").dialog(jQueryDialog1Opts);
                    $("#jQueryDialog1").html(data);
            },
            error:function (){
                alert("Error!!! Please refresh the page and try again!");
            }
        });
    });

I assumed your search script is in a php page named "search.php". Change it accordingly yup.



来源:https://stackoverflow.com/questions/31955642/display-search-results-in-modal-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!