Hi there, I have a db with only one table in it called "CONSULTANT". I'm
using sqlServer and would like to do record paging, say 5 at a time. I'm
aware that sqlServer doesn't support the LIMIT statement so I've decided to
do it using arrays.

So I've written the appropriate query statement, managed to grab details for
each consultant and dump that array into a new array called

Now, what I'd like to be able to do is this...return 5 records at a time.
Have 2 links called "next" and "previous" that when clicked adjusts the
$consultantarray accordingly.

Can someone take a look at my code below and tell me where I have to go from
here. So far the arrays are fine (meaning they are holding the appropriate
values), just the display of the appropriate records from the array is my
big problemo. :) I currently have a foreach loop being used, but am unsure
if this is the correct route to take, in fact, I know this isn't right
because it's displaying the records oddly.

Thx for your help, Joe :)


#connect to db
$connectionToDB = odbc_connect("cdxcet", "joecqon", "joecoqdsn");

#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);

print "<h4 align='left'><font color='#663399' face='verdana'>Consultant
Search Results for: " . $category . "</font></h4>";
#print out results here
#start the table -- loop through rows below
print "<table width='740' cellpadding='5' cellspacing='0' border='0'>";
print "<tr><td align='left' width='230'><font color='#663399'
face='verdana'><b>Name</b></font></td><td align='left' width='200'><b><font
color='#663399' face='verdana'>City</font></b></td><td align='left'
width='200'><b><font color='#663399'
face='verdana'>State/Province</font></b></td><td align='left'
width='200'><b><font color='#663399'
face='verdana'>Country</font></b></td><td align='left' width='200'><b><font
color='#663399' face='verdana'>Category</font></b></td><td align='left'
width='200'><b><font color='#663399' face='verdana'>Years
print "<tr><td height=10></td><td></td><td></td></tr>";

#initialize the consultant details array
$consultantdetailsarray[] = array();

// fetch the data from the database

  $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[] = $consultantdetailsarray;
 #forloop to iterate through array of consultants

foreach ($consultantarray as $value){
  $cid = $consultantdetailsarray[0];
  $firstname = $consultantdetailsarray[1];
  $lastname = $consultantdetailsarray[2];
  $city = $consultantdetailsarray[3];
  $stateprovince = $consultantdetailsarray[4];
  $country = $consultantdetailsarray[5];
  $category = $consultantdetailsarray[6];
  $yearsexp = $consultantdetailsarray[7];

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>";

print "</table><br><br>";

print "The count of the consultant array elements is : " .
count($consultantdetailsarray) . "<BR>";
print "The record count of returned consultants according to category
selected is : " . sizeof($consultantarray) . "<BR>";

  // close the connection


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