Hi,

I created a searchable "members directory" that probably dealt with some of
the issues you're dealing with ... though from your email I can't really
tell what exactly your application is for.

I'm not sure how professional or maintainable mine is, but here are some
basics of how I laid it out...

a) html form using post that is used to get the user's search parameters.
The user hits the submit button to submit their search parameters. The html
form uses post to call itself (ie the PHP page the form is on). 

You could use "GET", but all the values entered by the user would display as
part of the URL. The main issue might be that there is a limit to how long
your URL could be. If the user adds too many search parameters the URL might
become to long and you'd have a problem.

b) First the php script checks to see if search parameters have been
submitted. If yes, then an SQL statement is used to search a MySQL database.
For example, if the user wants to find all members with the last name "lee",
then the SQL statement looks for all members with the last name "lee" and
returns them sorted by one of the columns (in my case the column containing
the full name "last, first")

c) I create a two dimensional array of members that contains just their
member number. I want to display the members returned in pages of 10
entries, so the first dimension of the array contains the page number, and
the second dimension contains the item number on that page...here's the
code, I hope it makes sense...

         // create array of members numbers returned by search
         // note: first dimension is page number
         //       second dimension is page entry (up to 10 items per page)
         $pageNum = 1;
         $itemNum = 1;
         $totalNum = 0;
         while ($fieldsdirectory = mysql_fetch_array($resultdirectory))
         {
            $directoryresults[$pageNum][$itemNum] =
$fieldsdirectory["dir_addresses_memberid"];
            $itemNum++;
            $totalNum++;
            if (($itemNum-1) == 10) 
            { 
               $pageNum++;
               $itemNum = 1;
            }

         }
         // if the number of items is divisible by 10 we will have an extra
page
         if (($totalNum % 10) == 0) 
         { 
            $pageNum--;
         }

If you are displaying items one at a time, just create a one-dimensional
array -- much easier than the mess above!

d) When I display the results, I display the search form so the user can put
in another search, and below it the results. For mine, I don't use
first/last/prev/next, I just display links to the various pages in the
result set and add the variables needed to display those pages to the URL in
the html link (which calls itself). 

In your case, you would probably have a variable that keeps track of the
current entry. Knowing the current entry, you would be easily be able to get
the previous item and the next item (since it is an array). The first item
would be at index=0, and for the last item you could keep track of the total
number of items (or use a function to get the total number of items the
array).

If you think it might be useful, I can send you more of the code. I don't
however separate the PHP from the HTML which makes it a bit confusing and
I'm not sure how close this is to what you're looking for. This is pretty
much a one-person shop and keeping all the code together is probably less
confusing!

Rita.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 20, 2001 5:50 AM
To: [EMAIL PROTECTED]
Subject: Best foot forward?


Hi folks,

I have a requirement to show records in a certain standard 
format from a database. This requires first/previous/
next/last buttons, sorting on the column name, searching
and filtering using text entered into a text box etc etc.
This page would be continuously calling itself when
asked to sort or filter etc. and I wanted to use it as 
a generic display and search/sort page by passing in
an sql command or something along those lines.

This is getting too messy, i.e. using post and get, trying
to work with multiple subnmit buttons (anyone have any
example code here?), having multiple variables passed 
between pages or back into the same page. Can anyone 
tell me the best way to structure this? Should I always 
be using either post or get only, what's the best way to 
pass variables in this manner to ensure ease of maintenance 
and not letting it get messy (for example, should I be using 
an array of variables)? Is there an easier way?

If anyone of you has come across this before, could you 
please point a newbie in the right direction? Thanks.

Best Regards,

Colum Hickey

--------------------------------------------------------------------
Mail2Web - Check your email from the web at
http://www.mail2web.com/ .


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to