[Phpsig] Issue with web page display of MySQL values
bill
phpsig@kalamazoolinux.org
Thu, 12 Sep 2002 15:56:06 -0400
Glad to have helped.
So you're doing four queries to 1) get the info 2) get the total hits, 3) get a back
button and 4) get a forward button.
Here's how to get that down to one query.
Always display a BACK button unless it is the first page of the search. Eliminating
query 3 above.
To do NEXT buttons it is easier to just do a query with a limit of one more than what
you're displaying. If you're going to show a list of ten, query for eleven. Display
the ten. If there is an eleventh row, display a NEXT button. If not, don't. When
they click the NEXT button, just start your query at 11 and query to 21, etc. This
eliminates query 4 above.
You only need to do a full query (without LIMIT, query 2 above) if you're trying to
report the total number of hits or if you're trying to do like Google and display the
all the possible pages to jump to (so having 100 results would allow for jumping
directly to page 7 of the results, for example).
It's almost always easier to just do one query and do different things with the
results.
There are other ways, I've tried a few. But this seems easiest.
randall perry wrote:
> At 03:16 PM 9/12/2002 -0400, you wrote:
>
> >More questions:
> >
> >Why do you have four queries in lines 94 - 112 that are essentially the same?
> It was supposed to ease navigation when returning 1 page of info at a time.
>
> >For example, if you changed line 107 to be
> >
> >$num_rows = mysql_num_rows($show);
> >
> >you could eliminate an entire query (lines 96, 101, & 106).
> >
> >Why do all the queries only look at one table, ipaddress? Are you
> >intending on
> >getting information from the other tables site and device? If so, you
> >have to call
> >them, changing this:
> >
> >SELECT * from ipaddress WHERE $wherez LIKE \"%$search%\"
>
> This is EXACTLY what I was looking for!! Thanks Bill.
>
> >to this
> >
> >SELECT * from ipaddress, site
> >WHERE site_name LIKE \"%$search%\"
> >AND ipaddress.siteid=site.siteid
>
> Randall Perry
> www.fasnap.com
> www.davenport.edu
> www.domain-logic.com
>
> --------------------------------------------------------------------------------
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.385 / Virus Database: 217 - Release Date: 9/4/2002