-1

In this below code i want to display data in modal window .My aim is to display the searched data in modal dialog .Actual result is they are displaying above the form not in modal dialog.I have tried some steps but i cant able to produce the expected result pls help me.

<?php  
$search = (isset($_POST['search']) ? $_POST['search'] : null);

  mysql_connect("localhost", "root", "") OR die (mysql_error());
  mysql_select_db ("slseatapp") or die(mysql_error());

 $query = "SELECT * FROM coursemaster WHERE course_code LIKE '%$search%' or course_name like '%$search%'"; 

  $result = mysql_query($query) or die (mysql_error());

   $msg ;
     if($result) 
     {    
        while($row=mysql_fetch_row($result))   
       {      
            $msg=$msg ."ID=".$row[0].",COURSE CODE=".$row[1].",COURSE NAME=".$row[2];


       }   

        echo"<div id='overlay'>('$msg ');</div>";  
     }
   else
     { 
       echo "No result";  
     }
 ?>

<script>function overlay(){

el = document.getElementById('overlay');
el.style.visibility = (el.style.visibility == 'visible') ? 'hidden' : 'visible';

}function close() {
     document.getElementById('overlay').style.visibility = 'hidden';
}</script>
<style>#overlay div {
     width:300px;
     margin: 100px auto;
     background-color: #fff;
     border:1px solid #000;
     padding:15px;
     text-align:center;
}</style>"
<form action="look.php" method="post">  
 <center> SEARCH:<input type="text" name="search" placeholder="SEARCH"><br></center>  
 <center> <input type="submit" name="hhhh" class="btn-success btn"></center>
</form> 
  • You dont show how any of the JS shown is triggered. Any any case, if you want to show results in a modal dialog you need to have a call to JS alert() or similar function somewhere. A parameter to that call will need to be populated with your PHP search result. – spinkus Sep 16 '13 at 06:30
  • tell me wht have to change and where @Sam Pinkus – Moses Vickson Sep 16 '13 at 06:44

1 Answers1

-1

The problem seems to me that JS is not waiting DOM to be ready. One way to achieve this is to get this part of the code to the bottom of the php file.

<script>function overlay(){

el = document.getElementById('overlay');
el.style.visibility = (el.style.visibility == 'visible') ? 'hidden' : 'visible';

}function close() {
     document.getElementById('overlay').style.visibility = 'hidden';
}</script>

Since there is nothing coming from PHP on this part you don't have to wrap it as a string and don't have to echo in PHP, just put as it is.

ps. A friendly note here: The code seems a little bit messy. It is better to restructure it with separation of concerns, PHP-HTML, JS and CSS once it works.

CM.
  • 1,007
  • 1
  • 7
  • 19