Jump to content

Return search data to parent form/page?


jango

Recommended Posts

Hello,

 

Curious to know if someone could point me in the right direction, been struggling with this for a bit now.

 

I have a HTML page with a search field, I can enter a search term and hit the submit button and I am directed to my search.php page with the appropriate results. What I am looking to accomplish is having the search results from the search.php page displayed in a text area below my search field in my HTML page. I have included an image to better describe what I am looking to accomplish:

 

exampleki.jpg

 

Additionally below is the source from my HTML page and search.php page:

 

page.html

 

<form  name="search" action='search.php' method="post">
<input type="text" class="myinputstyle" name="search" value="search" onClick="this.value=''"/><br>
<input type="submit" value="submit" class="myinputstyle">
</form>

 

search.php

 

<?php
  $search = "%" . $_POST["search"] . "%";

  mysql_connect ("localhost", "game_over", "Ge7Ooc9uPiedee3oos9xoh4th");
  mysql_select_db ("game_over");

  $query = "SELECT * FROM game_over WHERE first_name LIKE '$search'";
  $result = mysql_query ($query);
  if ($result) {
    while ($row = mysql_fetch_array ($result)) {

    echo "Name: {$row['name']} " .
         "{$row['lname']} <br>" .
         "Email: {$row['email]} <br>" .
    }
  }
?>

 

Any insight would be most appreciated.

 

Thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/210499-return-search-data-to-parent-formpage/
Share on other sites

Well, I'd think you'll have to change up something a bit to get there.  Instead of echoing out the results in the search.php page, let's put them into an array and then store it in session.  There might be a better way, but I'm tired.  Alright, so:

 

Change the bottom of search.php (the while section) to something like this:

 

session_start();
$i=1;
while ($row = mysql_fetch_array ($result)) {
    $_SESSION['names'][$i] = "Name: {$row['name']} " . "{$row['lname']} <br>" . "Email: {$row['email]} <br>";
    $i++;
    }

 

Now, on your display page your textarea tag is going to look something like:

<textarea value="<?php for ($i=1; $i<=count($_SESSION['names']); $i++){echo $_SESSION['names'][$i]\n;} ?>"></textarea>

 

Somewhere around there, this is untested code, but it's either good or in the ballpark.

 

*EDIT: remember to add

<?php session_start; ?>

to the first line of your "page.html" if it isn't already there or you won't be able to pull the session variables.

I have attempted to implement those changes and have failed yet again, though through further research I had found the following code/posting which implements what I am trying to accomplish:

 

<?php
$action = $_POST['action'];

if (isset($action) )
{
   $name = $_POST['name'];
  if ($name=="Friday")
  echo "Have a nice weekend!"; 
elseif ($name=="Saturday")
  echo "Tomorrow is Sunday!"; 
else
  echo "Please enter Friday or Saturday"; 
}

?>

<form method="post" >
Name: <input type="text" size="10" maxlength="40" name="name"> 

<input type="submit" value="Send"> 
<input type="hidden" name="action" value="submitted">
</form>

 

From the following post:

 

http://www.phpfreaks.com/forums/index.php/topic,135555.msg571792.html#msg571792

 

I have attempted to implement the above stated code into my work and have been unable to successfully get it (the code) to do what I need.

 

Can anyone provide any insight into how I may utilize my code from my first posting in combination with the code from this posting to have my search results returned to a text field/area on my initial page?

 

Thank you.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.