Re: Search Engine a Problem...?

From: Date: Fri, 10 Nov 2000 22:21:00 +0000
Subject: Re: Search Engine a Problem...?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24730@lists.php.net to get a copy of this message
LIMIT rules - and you're really making things hard on yourself :O) (I'll try to make it easier!) Here is what I do... <? $LIMIT_PER_PAGE = 15; // strlen() is my sneak trick since // isset() and empty() sometimes fail on // 0 values ... if(!strlen($start)){ $start = 0; } $sql = "SELECT * FROM table WHERE type='$type' LIMIT $start,$LIMIT_PER_PAGE"; $r = mysql_query($sql); $total_rows = @mysql_num_rows($r); while($row = mysql_fetch_array($r)){ // you know the drill } if(($start + $LIMI_PER_PAGE) < $total_rows){ $start += $LIMIT_PER_PAGE; } if(($start - $LIMIT_PER_PAGE) > $LIMIT_PER_PAGE){ $prev = ($start - $LIMIT_PER_PAGE); } echo '<A HREF="'.$PHP_SELF.'?start='.$prev.'">Previous '.$LIMIT_PER_PAGE.' Records</A>'; echo '<A HREF="'.$PHP_SELF.'?start='.$start.'">Next '.$LIMIT_PER_PAGE.' Records</A>'; ?> My news package has some more in depth stuff pertaining to this - you can get it at http://www.miester.org/software --Joe On Fri, Nov 10, 2000 at 02:06:51PM -0800, Dhaval Desai wrote: > Hey Guys > > I have a really silly doubt. I wanted to know how the > following code works with limiting the mysql query > with the limit statement. > I have the following code here: > <?php > > $host= "localhost"; > $mainuser= ""; > $db=""; > > > #To use with LIMIT statement of Select > $numrecs=30; > > ### to check whether its the first page (page1) > if (empty($offset)) > { > $offset=0; > } > if (empty($lower)) > { > $lower=1; > } > if (empty($upper)) > { > $upper=$numrecs; > } > if (!empty($next)) > { > $lower += $numrecs; > $upper += $numrecs; > $offset += $numrecs; > } > if (!empty($prev)) > { > $lower -= $numrecs; > $upper -= $numrecs; > $offset -= $numrecs; > } > #To use with LIMIT statement of Select > > ******************************************************* > > > Now THIS IS THE PART I AM NOT ABLE TO UNDERSTAnd > > ******************************************************* > ## submitting two queries > ## one for page1 > ## second to find out the entire list > $query1="select * from $table1 where prodclass like > '%$keyword%' order by prodclass limit ". ($offset != 0 > ? "$offset, $numrecs" : "$numrecs"); > $query1a="select * from $table1 where prodclass like > '%$keyword%' order by prodclass"; > > > Please can anybody explain me the limit statement.. > > Thanx a lot! > > I am eagerly waiting for replies to this email. > > Dhaval Desai > > > > > > > > > __________________________________________________ > Do You Yahoo!? > Thousands of Stores. Millions of Products. All in one Place. > http://shopping.yahoo.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#24730) next »