Page 1 of 1

Remembering Search Queries

Posted: Thu Aug 03, 2006 6:44 am
by mick_otoole
Hey all, this is my first post here so be gentle!

I'm working with a database that has a list of companies in it. When the user authenticates he/she is given a list of all companies in the database. There is a search box whereby a user can search for specific companies. The problem that I'm having is that if there are more than 20 matches for a search string a <Next> button appears on the bottom of the page. When the user clicks on the next button the page that is displayed is not related to the original search query. I was wondering if anyone can help me out on how to display only relevant results on the <Next> page.

I hope this explains properly what I'm trying to do.

Thanks in advance for any help that you can give me.

Mick

Posted: Thu Aug 03, 2006 7:09 am
by mick_otoole
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I suppose it might be helpful if I posted my code ....
/* $Id: PageName.php,v 1.46 2006/08/03 12:40:41 Mick Exp $

Code: Select all

<?php
session_start() ;

require_once 'DB.php';
require_once 'functions.inc';
require_once 'HTMLGenerator.php';
require_once 'Client.inc';
require_once 'Order.inc';
require_once 'Constants.inc';
require_once $path_required_scripts.'Bizunit.inc';


$_SESSION['menu_to_display'] = 'clients';

pull_from_get('deleteclient','clientid','start','created');
pull_from_post('filter','form_clientname','form_filterbizunit');
pull_from_session('os_session_user_id');
if (!isset($os_session_user_id) || $os_session_user_id == NULL || $os_session_user_id == -1)
        header('Location: index.php');


foreach(array("form_clientname","filter","form_filterbizunit") as $variable)
        if (!isset($$variable))
                $$variable = "";

$params = array();
$strFeedback = "";

if (!isset($start)) $start = 0;

$display = $listdisplay;
$prev_value = $start - $display;
$next_value = $start + $display;
$recordCount = $display+1;
$showPrevNext = 'false';


//if "company" logged in, display all clients, else only clients for this reseller
if ($os_session_user_id == 1000)
        $reseller = "";
else
        $reseller = " and u.reseller_id = ".$os_session_user_id;

$strSelect = 'Select u.* from user u, client_information c where c.user_id = u.user_id and c.client_account_activated = 1 '.$r
eseller .' limit '. $start . ',' . $display;

if (isset($filter) && $filter == 'Search')
{

                 //$strSelect = "select * from client_information where client_company_name like ? or client_last_name like ?
or client_first_name like ?";

                $strTmp = "'%" . $form_clientname . "%'";
                $bizunitsql="";
                if((isset($form_filterbizunit)) && (!($form_filterbizunit==-1))) { $bizunitsql=" and c.bizunit=$form_filterbiz
unit";  };

                 $strSelect = "select c.* from client_information c, user u where c.user_id=u.user_id and c.client_account_act
ivated = 1 and (u.username like ".$strTmp . " or c.client_company_name like " . $strTmp . " or c.client_last_name like  " . $s
trTmp . "  or c.client_first_name like  " . $strTmp . ")".$reseller . $bizunitsql . " limit ". $start . "," . $display;

                $res1 =& getRecordSetMessengerDB("select count(*) from client_information c, user u where c.user_id = u.user_i
d and (c.client_company_name like " . $strTmp . " or c.client_last_name like  " . $strTmp . "  or c.client_first_name like  "
. $strTmp.") ".$reseller, $params);

                $row =& $res1->fetchRow();

                $recordCount = $row[0];

                //echo $strSelect;

                if ($recordCount > $display) $showPrevNext = 'true';

                //$params = array($form_filterorderid);
                //$params =  array("%" . $form_clientname . "%","%" . $form_clientname . "%","%" . $form_clientname . "%","%"
. $form_clientname . "%");
}


if (isset($deleteclient) && $deleteclient == 'true')
{
        $client = new Client();
        $client->deleteClient($clientid);
}

if (isset($created) && $created == 'new')
{
        $strFeedback = "Client and Client Account have been created successfully";
}

PrintHeader("OrderSystem -- Client Overview");
PrintLayoutTop("Client List", "Click on a Client Name to view the details", $os_session_user_id);

if ($strFeedback != "")
        echo '<div align=center><span class = "blue11">'.$strFeedback.'</span></div><br>';


?>



<form method="post" action="PageName.php">
<br>
<table border = 1 rules = none width = 50% align = center>
<tr>
        <td class=bold_text>Client Search</td>
        <td><input name="form_clientname" size = 13 value="<?php echo $form_clientname; ?>"></td>
</tr>
       <tr>
                <th class="bold_text" align=left>Biz Unit</th>
                <th class="bold_text" align=left>
                                                <select name=form_filterbizunit><option value='-1'></option>
                                                <?php
                                                        $bizunit = new Bizunit();
                                                        $bizunits = $bizunit->getBizunitIDList();

                                                        for ($i=0; $i < count($bizunits); $i++)
                                                        {
                                                                        $strSelected = "";
                                                                if ($bizunits[$i]==$form_filterbizunit) { $strSelected=" SELEC
TED "; };

                                                                $bizunit = new Bizunit($bizunits[$i]);
                                                                echo '<option value=' . $bizunits[$i] . ' ' . $strSelected.'>'
 . $bizunit->getBizunitName() . '</option>';
                                                        }
                                                ?>
                                        </select>

</th>
                <th class="bold_text" align=left><input type="submit" name="filter" value="Search"></th>
        </tr>

</table>
</form>

<br>
<?php


        $res =& getRecordSetMessengerDB($strSelect, $params);
        ?>

 <table width= 100% border="1" rules = rows class="text" align="left">
        <tr>
                <th class=greybg align="left">Username</th>
                <th class=greybg align="left">Company</th>
                <th class=greybg ></th>
                <th class=greybg ></th>
        </tr>

        <?php
        $i = 0;
        while ($row =& $res->fetchRow())
        {

                $strBackground = "";

                $user = new Client($row[0]);

                ?>
                <tr <?php echo $strBackground; ?> >
                        <td>
                          <a title = "Edit Client" href= "EditClient.php?<?php echo "clientid=" . $row[0] ?>"> <?php echo $use
r->getClientUsername(); ?> </a>
                        </td>
                        <td>
                          <?php echo $user->getClientCompanyName(); ?>
                        </td>
                        <td>
                          <a title="display client's orders" href = "OrderOverview.php?<?php echo "clientid=" . $row[0] ?>">ge
t orders</a>
                        </td>
                        <td>
                          <a title="Delete Client" href= "PageName.php?<?php echo "deleteclient=true&clientid=" . $row[0
] ?>" >x</a>
                        </td>
                </tr>


        <?php
        }

        ?>

        </table>
        <div style = "color:white">a</div>
        <table width=100%>

        <tr>

                <td width=90%></td>
                <td width=10%>

                        <?php
                        if (($recordCount > $display) || ($showPrevNext == 'true'))
                        {
                                if ($start > 0)
                                {
                                ?>
                                        <a href = "PageName.php?start=<?php echo $prev_value;?>"> prev </a>
                                <?php
                                }
                                ?>

                </td>
                <td>

                                        <a href = "PageName.php?start=<?php echo $next_value;?>"> Next </a>
                        <?php
                                }
                                ?>

                </td>
        </tr>

        </table>

<?php
PrintLayoutBottom();
PrintFooter();
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 03, 2006 7:42 am
by mick_otoole
I can see from the code

Code: Select all

if (!isset($start)) $start = 0;
$display = $listdisplay;
$prev_value = $start - $display;
$next_value = $start + $display;
$recordCount = $display+1;
$showPrevNext = 'false';
That the next button will just take the start and add on the $listdisplay basically abandoning the search query completely. I'm still trying to figure out how to pass the query through the next button.

Anyone ??? Please? I'm going frigging nuts trying to figure this out!