Why don't you ask the question on a SQL Server list? This isn't a put down, 
or an attempt to shove you away, but if you can do this in MSFT's 
TRANSACT-SQL you will be offloading the work to the database engine which 
is designed to do it.

Alternately, can you use two queries, the first which uses TOP, and a 
second which also uses top and fetches greater than previous result. That 
would also have the advantage of returning small data sets, faster.

Regards - Miles Thompson

At 03:24 PM 1/12/2002 -0400, Joe Van Meer wrote:
>Hi there, I have a small php/data driven website and would like to
>incorporate record paing. Unfortunately I'm working with sql Server
>temporarily, but I'm still required to do this. So since I wasn't allowed to
>use the handy LIMIT in my sql statement I figured I'd dump my results into a
>mulitdiensional array and navigate through the records that way. I know this
>propbabbly isn't the best method, but it's the way I have to do it for now.
>I've managed to display my records out of the array, but would now like to
>incorporate a "next' and a 'previous' button to navigate through the array.
>Can someone take a look at my code below and tell me how I'm to go about
>doing this? I thought maybe by having 2 functions that would advance my
>array pointer and another to retreat the pointer would do the trick. I'm
>unsure how to incorporate it. I've added two functions within the
>************ below, not sure if they are appropriate or not though.
>
>Thx Joe :)
>
>
>
>
>
>
>Code:
>if(!isset($consultantarray)){
>
>
>//connect to db
>$connectionToDB = odbc_connect("cdxcffcoltant", "jo7gecon", "josje7con");
>
>//create query statement
>$sqls = "SELECT consultantid, firstname, lastname, city, stateprovince,
>country, category, yearsexp FROM CONSULTANT WHERE category ='$category'
>ORDER BY yearsexp DESC" ;
>
>//execute the sql statement (query) on the connection made
>$resultset = odbc_do($connectionToDB, $sqls);
>
>
>
>
>//initialize the consultant arrays
>$consultantdetailsarray[] = array();
>$consultantarray[] = array();
>
>//initialize a variable to zero for start of array below in while loop
>$x = 0;
>
>// while there is still results fetch the data from the database --- while
>loop
>while(odbc_fetch_row($resultset)){
>
>   $consultantdetailsarray[0] = odbc_result($resultset, 1);
>   $consultantdetailsarray[1] = odbc_result($resultset, 2);
>   $consultantdetailsarray[2] = odbc_result($resultset, 3);
>   $consultantdetailsarray[3] = odbc_result($resultset, 4);
>   $consultantdetailsarray[4] = odbc_result($resultset, 5);
>   $consultantdetailsarray[5] = odbc_result($resultset, 6);
>   $consultantdetailsarray[6] = odbc_result($resultset, 7);
>   $consultantdetailsarray[7] = odbc_result($resultset, 8);
>
>
>
>
>//dump each consultant into the new array called $consultantarray
>   $consultantarray[$x] = $consultantdetailsarray;
>
>  //increment to next element of array
>   $x++;
>}
>
>}
>
>
>****************************************************************************
>*
>function nextFive(&$array, $number){
>for ($counter = 0; $counter < $number; $counter++){
>next($array);
>
>}
>}
>
>
>
>
>function previousFive(&$array, $number){
>for ($counter = 0; $counter < $number; $counter++){
>prev($array);
>}
>}
>
>
>****************************************************************************
>*
>
>//loop through the elements of retrieved array (2nd one holding the
>consultant details)
>
>  //second loop to grab through $consultant details array elements
>  foreach($consultantarray as $y){
>
>  list($cid, $firstname, $lastname, $city, $stateprovince, $country,
>$category, $yearsexp) = $y;
>
>  print "<tr><td align=left><font color='#663399' face='verdana' size=2><a
>href='consultantdetails.php?cid=" . $cid . "'>"  . $firstname . " " .
>$lastname . "</a></font></td><td align=left><font color='#663399'
>face='verdana' size=2>" . $city . "</font></td><td align=left><font
>color='#663399' face='verdana' size=2>" . $stateprovince . "</font></td><td
>align=left><font color='#663399' face='verdana' size=2>" . $country .
>"</font></td><td align=left><font color='#663399' face='verdana' size=2>" .
>$category . "</font></td><td align=left><font color='#663399' face='verdana'
>size=2>" . $yearsexp . "</font></td></tr>";
>
>
>  }
>
>
>
>
>
>
>--
>PHP General 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]


-- 
PHP General 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