Pages: [1]   Go Down
Send this topic | Print
Author Topic: [RESOLVED] Get form results to display on the same page as the form!  (Read 1412 times)
gwynevere
Active Member
**
Offline Offline

Posts: 54


WWW
« on: September 11, 2008, 01:25:35 PM »

Okay, I've looked on google, but the tutorials I've tried were a bit confusing and some simply didn't work at all...

After some playing around, I finally got one to work. Though.. the only thing is... I know that when it retrieves the results.. it'll print out the information on a new page. So my question is... how do I combine the two parts.. and get the form to print out the results on the same page BELOW the form?

Here is what the form code looks like within the BODY:

Code:
<div id="listings">

<form method="get" action="./searchname.php">
<input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="Search by Dragon Name!">
</form>

</div>


Here is the script that the form uses:

Code:
<?php

  $var
= @$_GET['q'] ;
  
$trimmed = trim($var);

$limit=1;

if (
$trimmed == "")
  {
  echo
"<p>Please enter a search...</p>";
  exit;
  }

if (!isset(
$var))
  {
  echo
"<p>Dragon not found!</p>";
  exit;
  }

mysql_connect("localhost","gwynevere_blah","blah"); //(host, username, password)

mysql_select_db("gwynevere_landf") or die("Unable to select database"); //select which database we're using

$query = "select * from lostandfound where dragon like \"%$trimmed%\"  
  order by dragon"
;

 
$numresults=mysql_query($query);
 
$numrows=mysql_num_rows($numresults);

if (empty(
$s)) {
  
$s=0;
  }

$query .= " limit $s,$limit";
  
$result = mysql_query($query) or die("Couldn't execute query");

$count = 1 + $s ;

while (
$row= mysql_fetch_array($result)) {
  
$dragon = $row["dragon"];
  
$code = $row["code"];
  
$owner = $row["owner"];
  
$forum = $row["forum"];

  echo
"$count.) Dragon Name: $dragon <br />";
  echo
"Code: <a href=http://dragcave.net/viewdragon/$code target=_blank>VIEW DRAGON</a><br />";
  echo
"Owner: <a href=http://dragcave.net/user/$owner target=_blank>$owner</a><br />";
  echo
"Forum Contact: $forum";
  
  
$count++ ;
  }
  
?>

Here is the page I have the form on:

http://gwynevere.110mb.com/lostandfound.php

As I mentioned, I want the results to be printed out BETWEEN the two forms.. but I haven't a single clue on how to use what I've learned in PHP to do that. If I could get some help, that'd be great! Thanks!!

« Last Edit: September 11, 2008, 09:32:31 PM by gwynevere » Logged
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« Reply #1 on: September 11, 2008, 01:48:38 PM »

Where the form code is, use this instead:

Code:
<div id="listings">

<form method="get" action="lostandfound.php">
<input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="Search by Dragon Name!">
</form>

</div>

<?php

if (@$_GET['q']) {

&
#160; $var = $_GET['q'] ;
&#160; $trimmed = trim($var);

$limit=1;

if (
$trimmed == "")
&
#160; {
&#160; echo "<p>Please enter a search...</p>";
&#160; exit;
&#160; }

if (!isset($var))
&
#160; {
&#160; echo "<p>Dragon not found!</p>";
&#160; exit;
&#160; }

mysql_connect("localhost","gwynevere_blah","blah"); //(host, username, password)

mysql_select_db("gwynevere_landf") or die("Unable to select database"); //select which database we're using

$query = "select * from lostandfound where dragon like \"%$trimmed%\"&#160;
&#160; order by dragon"
;

 
$numresults=mysql_query($query);
 
$numrows=mysql_num_rows($numresults);

if (empty(
$s)) {
&
#160; $s=0;
&#160; }

$query .= " limit $s,$limit";
&
#160; $result = mysql_query($query) or die("Couldn't execute query");

$count = 1 + $s ;

while (
$row= mysql_fetch_array($result)) {
&
#160; $dragon = $row["dragon"];
&#160; $code = $row["code"];
&#160; $owner = $row["owner"];
&#160; $forum = $row["forum"];

&#160; echo "$count.) Dragon Name: $dragon <br />";
&#160; echo "Code: <a href=http://dragcave.net/viewdragon/$code target=_blank>VIEW DRAGON</a><br />";
&#160; echo "Owner: <a href=http://dragcave.net/user/$owner target=_blank>$owner</a><br />";
&#160; echo "Forum Contact: $forum";
&#160;
&#160; $count++ ;
&#160; }

}
?>


It's untested but should work.
Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
gwynevere
Active Member
**
Offline Offline

Posts: 54


WWW
« Reply #2 on: September 11, 2008, 09:33:16 PM »

Thank you Myles! This is the third time you've helped me! I appreciate it! Works wonderfully!
Logged
Pages: [1]   Go Up
Send this topic | Print
Jump to: