Jump to content

Recommended Posts

Hello everyone,

 

I've been a reading this forum for sometime, but this is my first post. First of all, thank you to everyone who answers questions for those of us that are banging our heads on the wall.  :facewall:

 

OK, so here is my question. I want to save the field that the user last used when doing a search. I have two files: header.php and index.php

 

header.php

<?php
echo '
<a href="index.php"><img border="0" src="Home.png" width="120" height="19"></a>
<a href="add.php"><img border="0" src="AddRecord.png" width="120" height="19"></a>
<a href="printstrings.php"><img border="0" src="PrintStrings.png" width="120" height="19"></a>
';
?>

 

index.php

<head>
<script src="sorttable.js" type="text/javascript"></script>
<style type="text/css">
td {
empty-cells: show;
}

html, body{ 
   background-image:url(Back01.jpg); 
} 


</style>

<link rel="stylesheet" type="text/css" href="ltn.css" />

</head>
<div align="center">
<?php include("password_protect.php"); ?>
<?php include 'header.php'; ?>
</div>

<div align="center">
<form name="form" action="index.php" method="get">
Search for <input type="text" name="q" />  in field
<select name="field">
      <option value="USERNAME">Username</option>
      <option value="PORT">Port and Controller</option>
      <option value="PRINTNAME">Print String</option>
      <option value="NTTLIVE">NTT Live</option>
      <option value="LOCATION">Location</option>
      <option value="TERMNAME">Termname</option>
      <option value="SERIALNO">Serial Number</option>
      <option value="IPADDRESS">IP Adress</option>   
      <option value="NOTES">Notes</option> 
      
</select>

  <input type="submit" name="Submit" value="Search" />
</form>
</div>
<?php


if (@$_GET['q']) {
///// Get the search variable from URL
  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable
  $field = $_GET['field'];


////// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

///// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

/////connect to database 
mysql_connect("localhost","phi","shhphi!"); //(host, username, password)

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

///// Build SQL Query  
$query = "select * from practiceltn where $field like \"%$trimmed%\"  
  order by $field"; // EDIT HERE and specify your table and field names for the SQL query


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


// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

  }
else
{

// get results

  $result = mysql_query($query) or die("Couldn't execute query");

// begin to show results set


echo '
<table class="sortable" border="1" cellpadding="1" cellspacing="0">
<thead bgcolor="white">
<tr>
  <th>Edit</th>
  <th>User Name</th>
  <th>IP Address</th>
  <th>Computer Name</th>
  <th>Serial Number</th>
  <th>Make/Model</th>
  <th>Location</th>
  <th>Port</th>
  <th>NTT Live</th>
  <th>Printstring</th>
  <th>FAMIS</th> 
  <th>Deploy Date</th>
  <th>Notes</th>
</tr>
</thead>';

echo '<tbody>';
$color="1";
// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {

// Convert GTWAY number to it's logical statement
switch ($row['GTWY'])
{
case 0:
    $gateway = 'TSHEC';
    break;
case 1:
    $gateway = 'T1121D';
    break;
case 2:
    $gateway = 'T112B2';
    break;
case 3:
    $gateway = 'T112B3';
    break;
case 4:
    $gateway = 'T112B4';
    break;
default:
    $gateway = ''; 
    break;
}
// Setup the alternating colors
if($color==1){
echo "
<tr bgcolor='#dbe7ed'>
  <td><a href='ltnupdate.php?id=".$row['LTN_ID']."'><img src='app_48.gif' align='center'></a></td>
  <td>".$row['USERNAME']."</td>
  <td> <a href='http://".$row['IPADDRESS'].":5800'</a>" .$row['IPADDRESS']."</td>
  <td>".$row['TERMNAME']."</td>
  <td>".$row['SERIALNO']."</td>
  <td>".$row['MAKE']."  ". $row['MODEL']."</td>
  <td>".$row['LOCATION']."</td>
  <td>".$row['PORT']."</td>
  <td>".$row['NTTLIVE']."</td>
  <td>".$row['PRINTNAME']."</td>
  <td>".$gateway. $row['MIS1MIS2']."</td>
  <td>".$row['PROBDATE']."</td>
  <td>".$row['NOTES']."</td>
</tr>";  

$color="2";
}
else {

echo "
<tr bgcolor='#9bbde0'>
  <td><a href='ltnupdate.php?id=".$row['LTN_ID']."'><img src='app_48.gif' align='center'></a></td>
  <td>".$row['USERNAME']."</td>
  <td> <a href='http://".$row['IPADDRESS'].":5800'</a>" .$row['IPADDRESS']."</td>
  <td>".$row['TERMNAME']."</td>
  <td>".$row['SERIALNO']."</td>
  <td>".$row['MAKE']."  ". $row['MODEL']."</td>
  <td>".$row['LOCATION']."</td>
  <td>".$row['PORT']."</td>
  <td>".$row['NTTLIVE']."</td>
  <td>".$row['PRINTNAME']."</td>
  <td>".$gateway. $row['MIS1MIS2']."</td>
  <td>".$row['PROBDATE']."</td>
  <td>".$row['NOTES']."</td>
</tr>";  
  $color="1";
}


  }

echo "</tbody><table>";
}

};
?>

 

What I'm looking for is when some searches for something on the index, and they click the Home link (called from header.php) that it will keep the last field that hey searched for.

 

I hope I've explained this correctly and thanks for the help!!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/168288-set-field-with-_get/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.