Jump to content

Need Help Adding A Search Function To This Page/Code


TG SH4RPY

Recommended Posts

Well basically i want to add a search function, so i can search by name or status, can anyone help me?

 

 

Here's the code :

 

<?php

if ( ! defined( 'IN_IPB' ) )

{

print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";

exit();

}

//All reports run inside the load_options ATS Form - don't setup any others unless your intention is to run outside of the ATS wrapper and security

class ats_mod

{

var $ipsclass; //store the IPB super class object for use

var $funct; //load the common functions object (had to be an object so we can pass it to other class objects later)

 

function run_me()

{

$query_where = "d_name LIKE '%'";

$id_remember = "";

if ($this->ipsclass->input['show'] != Null)

{

$g_showa = explode(" ", $this->ipsclass->input['show']);

 

$id_remember = "&show=" . $this->ipsclass->input['show'];

$query_where = "";

$show_count = count($g_showa);

foreach ($g_showa as $key => $value)

{

$query_where .= "d_id = $value";

if ($show_count > 1)

{

$query_where .= " OR ";

}

$show_count--;

}

 

}

switch ($this->ipsclass->input['sort'])

{

case 'name' :

$sort_string = "d_name ASC, d_date ASC";

break;

case 'date' :

$sort_string = "d_date DESC, d_name ASC";

break;

case 'ip' :

$sort_string = "d_ip ASC, d_name ASC";

break;

case 'type' :

default :

$sort_string = "d_status ASC, d_name ASC";

break;

}

 

$this->ipsclass->DB->simple_construct( array( 'select' => '*',

'from'  => 'members_discharges',

'where' => $query_where,

'order'  => $sort_string ));

$this->ipsclass->DB->simple_exec();

 

print ("<TABLE BORDER CELLPADDING=4>

<TR ALIGN=CENTER VALIGN=TOP>

<TH ALIGN=CENTER VALIGN=TOP COLSPAN='7'>{$this->funct->board_name} Discharges and Rejected Validations</TH>

</TR>

<TR ALIGN=CENTER VALIGN=TOP>

<TH><a href='http://{$this->funct->board_site}/index.php?autocom=ats&code=wrapper&ats=run_option&atsmodule={$this->mod_number}&sort=type$id_remember'>Type</a></TH>

<TH><a href='http://{$this->funct->board_site}/index.php?autocom=ats&code=wrapper&ats=run_option&atsmodule={$this->mod_number}&sort=name$id_remember'>Member Name</a></TH>

<TH><a href='http://{$this->funct->board_site}/index.php?autocom=ats&code=wrapper&ats=run_option&atsmodule={$this->mod_number}&sort=ip$id_remember'>IP Address</a></TH>

<TH>Other Known Names</TH>

<TH NOWRAP><a href='http://{$this->funct->board_site}/index.php?autocom=ats&code=wrapper&ats=run_option&atsmodule={$this->mod_number}&sort=date$id_remember'>Discharge Date</a></TH>

<TH>Reason(s)</TH>

<TH>Comments/Details</TH>

</TR>

");

 

 

while ( $r = $this->ipsclass->DB->fetch_row() )

{

$ddate = date("Y-m-d", $r['d_date']);

$onames = implode(",<BR>\n",explode(",", $r['d_other_names']));

$reason = implode(",<BR>\n",explode(",", $r['d_reason']));

if ($r['d_bday_year'] != NULL)

{

$reason .= "<BR>\nBirthday:<BR>\n" . $r['d_bday_year'] . "-" . $r['d_bday_month'] . "-" . $r['d_bday_day'];

}

$comments = str_replace(array("\r\n", "\n", "\r"), "<br />", $r['d_comments']);

 

print ("<tr>

<td>{$r['d_status']}</td>

<td>{$r['d_name']}</td>

<td>{$r['d_ip']}</td>

<td>{$onames}</td>

<td>{$ddate}</td>

<td>{$reason}</td>

<td>{$comments}</td>

</tr>

");

}

print("</table>");

}

}

?>

Link to comment
Share on other sites

If you're trying to search for data in your mysql tables, it's pretty simple. You can set up an isset and create a search form somewhere on the page.

 

such as:

 

if (isset($_POST['search']))
   {
(sql code here to search your database)
   }
... rest of script ...

 

and then somewhere in the script, you'd simple create a search form:

 

<form method="post" action="thispage.php"> (thispage being whatever page you're on)
echo "Search: <input type='text' name='query' size='20'><br>";
echo "<input type='submit' name='search' value='Go!'></form>";

 

So you would do a normal SQL search where (what they're looking for) LIKE %$query%

 

Know what I mean?

Link to comment
Share on other sites

So it would look like this?

 

<form method="post" action="class_report_discharges.php">

echo "Search: <input type='text' name='query' size='20'><br>";

echo "<input type='submit' name='search' value='Go!'></form>";

 

if (isset($_POST['search']))

  {

($r['d_name'])

  }

Link to comment
Share on other sites

So it would look like this?

 

<form method="post" action="class_report_discharges.php">

echo "Search: <input type='text' name='query' size='20'><br>";

echo "<input type='submit' name='search' value='Go!'></form>";

 

if (isset($_POST['search']))

  {

($r['d_name'])

  }

 

What I am saying is, you need to know what is being searched for. For example, if you're trying to search for any records that have xxxxx in them in the d_name field, you would use that search form and then this:

 

if (isset($_POST['search']))
   {
$query=$_POST['query'];
$sql="select * from tablename where d_name like %".$query."%";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
        {
echo "Name: ".$row['d_name']."\r\n";
echo "whatever: ".$row['whatever']."\r\n";
         }
    }

 

just make sure you have some kind of cleaning function to clean the data that people are sending on the form or you could be open to sql injection :/

Link to comment
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.