Hey All,

Ok well im trying to create code that will basically take data from a search open in a new window and list all the records from the mysql database that have the letters or words in it like for example say "george" is in the database, i want it so when you type "geo" or something along those lines and press the button search, it will then open a new window with all the records showing but show at the top the best matched then list the second best and so one while listing the rest alphabetically after if you know what I mean then when you click on it I want it to exit the window and then populate the forms with their information.

Can someone please help me I'm kind of stuck here 😕!

Thanks DB_Guy

    Hey,

    Ook if no one is following me I can re-word it and explain in a little more detail.

    Just a little update , I have got most of it to work just having a problem with the last part to work...

    Ok first of all I have two pages one that has all forms on it let's call it page1 and the other page is used to search and display the records lets call that page2,

    page1(the form page) is where you imput the word you want to search for
    page2(search page) is the window that pops up and is supposed to list all the matches from the search

    So far I have it so that when you click the button "search" on page1 it opens a new window(page2) and lists all of the records on it.

    The part that is not working is ..the search part like when you type something in the search box and press "search" it doesn't show the best matches for what you put in because it is not passing the variable "var1" lets call it, through from page1 to page2 is what I believe is going wrong

    so instead of listing all the records that match the search word it just lists all the names and everything which is not what I want, could someone help me out please! 😕

    it would be most appreciated

    P.S. if that is still too confusing or if you need clarification please do not hesitate to reply to this and tell me so ..

    thanks in advance for all your help and for taking time to read this 🙂

      You are being unclear on what you need to accomplish.

      You say that "var1" from "page1" is not being passed to "page2". Why not? On "page2" you should be calling the variable into your search query via GET, POST, or REQUEST.

      If your question is more along the lines of how to display only the results you want, I think you should look into the "LIKE" command. For example, you could use the following query to search for "var1" from "page2"

      SELECT * FROM `MyTable` WHERE `MyField` LIKE '%' . $_POST['var1'] . '%';
      

      See MySQL String Comparison Functions for more information.

      http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

      Hope this helps.

        Hey ALL,

        first of all thanks for all your help,

        Ok I'll try an explain this a little better when I echo out to see if the variable is being passed onto page2 which is the search page, it shows nothing is being passed

        Here is the top of my code ....

        $var1 = &$_POST['var1'];
        
        echo "
        Variable 1: $var1<br />
        ";
        
        
        $sql = "SELECT var1, var2, var3, var4 
        FROM table1
        WHERE var1 
        LIKE '%$var1%'
        ORDER BY var3 ASC";
        
        
         $result = mysql_query($sql) or die ("Blah blah blah!");

        it comes out like ...

        Variable 1 :

        then lists all of the records in a table.

        so I think the variable isnt being passed or something. :queasy:

        Any suggestions? 😕

          So do a var_dump() of $_POST and see what you are receiving in the post data. If nothing, then go back to the form page and make sure the form is using the post method.

            I tried the var_dump every way and got pretty much nothing

            var_dump($_POST);
            

            outputted: array(1) { ["var1"]=> & NULL }

            then

            var_dump($_POST['var1']);
            

            outputted: NULL

            and finally I tried..

            var_dump($var1);
            

            outputted: NULL

            any suggestions on what I should do?

            I already double checked that the form was post and it is on page1

            so I'm lost again :queasy:😕

              Go back to the form and make sure the method="post" and that var1 is actually set as the name to the element you want to retrieve (the input box I suspect).

              <form action="search.php" method="post">
                  <label for="terms">Search:</label>
                  <input type="text" id="terms" name="var1" />
                  <input type="submit" name="submit" value="Go!" />
              </form>

              If you're doing it via Javascript, make sure that it's actually posting the data to the new page, and not using the URL (because $POST != $GET).

              If all else fails, you could var_dump($REQUEST) to see if var1 is in fact in the $POST or $_GET arrays.

                Thanks this what I have for page1 for the variable1 form...

                <form name="form" method="post">    
                <tr> <td align="right">Variable1:</td> <td><input name="var1" type="text" id="var1" size="50" maxlength="50" value="<?php if (isset($_POST['var1'])) echo stripslashes($_POST['var1']); ?>" tabindex="4" /> <input align="left" type="submit" name="Submit" value="Search" onclick="window.open('page2.php', 'pageWin', 'width=660,height=500,scrollbars=yes')" tabindex="12" /> </td> </tr> </form>

                  You're not posting anything... just opening a window on button press.......

                    oh really? didn't see that thanks for pointing that out wow I feel a little dumb lol , do you know how I would go about doing this by posting ? Because I am not to sure, how to go about it..?:queasy:

                      Your form is missing an action.

                      <form method="POST" action="/path/to/page2.php">

                      If you use onClick to open page2.php in a new window, you will also have to use JavaScript to read the form variables and pass them to page2.php via GET.

                        hmm not sure I'm following 100 % i understand prett ymuch what your saying just confused about how I am going to do that can you give me some guidance please ...

                        and I don't want the page to change to page2 when i click submit I want page1 to stay like it is but open a new window and display page2 because when i put the action = the path to the page2 it changes page1 and opens a new window

                        what can i do to fix this?:queasy:

                          Well, if you want it in a new window, you can do that easily with

                          <form target="_blank">

                          If you want a javascript popup window, you might have to experiment with onsubmit.

                          <form onSubmit="window.open('page2.php', 'pageWin', 
                          'width=660,height=500,scrollbars=yes')">

                          I have no idea if that will work or not, try it and let me know.

                          OR perhaps another idea, if you do not have a lot of form inputs, you can pass them via GET. Then on page2.php instead of looking for POST['var1'] you look for GET['var1']

                          <form onSubmit="window.open('page2.php?var1='+document.getElementById('var1').value+'','pageWin','width=660,height=500,scrollbars=yes')">

                          Again, no idea if that will work, just giving you ideas to test. What you really want is AJAX.

                            yes, unfortunately none of those worked, its funny though when it was changing page1 to page2 it was working the way it should, so it's definitely the variable "var1" is not passing over to the other page and I have like no clue what to do to make this happen, i've tried many things none of which have worked even tried creating a session, nothing has yet to work though... :queasy:😕

                              Hey all,

                              Thanks for all your continued help I got one part of that solved , thanks to your help and some help from Google and such (I used a session variable to carry it over).

                              Anyways I just have one thing left to do which I could use a hand on I've tried looking for how to do this but haven't had any luck so far and not sure how to word it but here goes....

                              Now that I have it so when you type an abbreviation or code and click search it pops up with a window(page2) which displays all the results. I now need to find a way to be able to click on a cell in the table and have the persons information come up on page1 and populate the forms with the information.

                              If you have any ideas or even and links to websites that may be of assistance it would be most appreciated.. 🙂

                              P.S. If any of this is unclear or you need more information / further explanation of what is needed to be accomplished, don't hesitate to ask me by posting it here or message..

                              Thank You
                              DB_Guy

                                You should read up on AJAX.

                                  Actually, you might try something like this:

                                  /* if this function returns true, the form will be submitted
                                     if it returns false, the form won't */
                                  <script type="text/javascript" >
                                  function submitHandler(frm) {
                                      /* the second argument must match the target attribute of the form.  This will
                                         open the window that is the target of the form submission */
                                      window.open('page2.php', 'myWindowName', 'width=660,height=500,scrollbars=yes');
                                  
                                  return true;
                                  }
                                  </script>
                                  <form method="post" action="page2.php" target="myWindowName" onsubmit="return submitHandler(this)">
                                  <input name="var1" type="text" id="var1" size="50" maxlength="50"  value="<?php if (isset($_POST['var1'])) echo stripslashes($_POST['var1']); ?>" tabindex="4" />
                                  <input align="left" type="submit" name="Submit" value="Search" />
                                  </form>
                                  

                                    Hey again,

                                    I'm not quite sure you are understanding what I am looking for , but perhaps that is my fault. I will try and reword it better and expand on it.

                                    Ok , this is what is happening. I have page1.php which is the initial page that displays all the form and at the top has the search form, the user types into the search box a code, clicks search it then opens a pop up window(aka page2.php), which displays the search results in a table. The user then clicks on whichever record or row they would like, and the pop up window then should close and populate the forms which are on page1.php

                                    The part I am having trouble with is setting it so when you click on a record it will exit the pop up window and populate the persons data in the forms on page1.php :queasy:😕 I'm not that familiar with JavaScript so please be a little patient with me, thanks

                                    Can anyone help me out here, any help is greatly appreciated thanks again..

                                    & Thank you all again for the continued help

                                    appreciate it 🙂