Jump to content

missing first row from query results


natronp

Recommended Posts

Ok, i thought i had straightened this out, but now I'm missing the first row from my query again.  I'm sure i'm making some noobish mistake.  I can trace out the # of rows with mysql_num_rows and it is correct.  My loop seems to omit the first row however.  code:

 

function listPhysByAlpha($sv){

//put these in here for testing, was thinking that variables weren't being re-instantiated on function call
$totalpages=0;
$r = 0;
$numrows = 0;

$result = mysql_query("SELECT * FROM physicians WHERE  lastName LIKE '".$sv."%' ORDER BY lastName") or die(mysql_error());

$numrows = mysql_num_rows($result);

echo "rows: ".$numrows;  //traces correctly

//bunch of stuff goes here for pagination

$i = 0;
// while there are rows to be fetched...
while($info = mysql_fetch_array( $result )) 
{ 
$i++;
if ($i % 2) {echo "<div id='listA'>";}else {echo "<div id='listB'>";}
echo "<table width='424' border='0' cellspacing='0' cellpadding='0'><tr><td width='63' valign='top'><div style='text-align:center'><div id='physPhoto'><img src='images/physPhotos/thumbs/".$info['photo']."' width='62' height='67' /></div></div></td><td width='6'></td><td width='290' valign='top'><span class='physName'>".$info['firstName']." ".$info['lastName']."</span><br/><span class='physSpecialty'>".$info['specialty1']." ".$info['specialty2']."</span><br/><span class='physLocation'>".$info['location']."</span></td><td width='65' valign='top'><span class='physLink'>view bio</span></td></tr></table>";
echo "</div><img src='images/oneTrans.gif' width='1' height='4'/>";
}
echo "<br/><br/>";

//bunch of stuff for pagination goes here as well



}


Link to comment
https://forums.phpfreaks.com/topic/188333-missing-first-row-from-query-results/
Share on other sites

Thanks for replying guys.  Teynon:  I've checked the database directly and I am definitely dropping the first row somewhere.

 

PFMaBiSmAd:  here is the entire function (yikes);

function listPhysByAlpha($sv){

$totalpages=0;
$r = 0;
$numrows = 0;

$result = mysql_query("SELECT * FROM physicians WHERE  lastName LIKE '".$sv."%' ORDER BY lastName") or die(mysql_error());
//$r = mysql_fetch_row($result);
//$numrows = $r[0];

$numrows = mysql_num_rows($result);

echo "rows: ".$numrows;

// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

//------------------pag links
if ($numrows > 10)
{
echo "what's up doc? ".$numrows." ".$totalpages;
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='http://mydomain/mypage.html?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='http://mydomain/mypage.html?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='http://mydomain/mypage.html?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='http://mydomain/mypage.html.html?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='http://mydomain/mypage.html.html?currentpage=$totalpages'>>></a> ";
} // end if
}//end if
//------------------end pag links
echo "<br/><br/>";
// get the info from the db 
$i = 0;
// while there are rows to be fetched...
while($info = mysql_fetch_array( $result )) 
{ 
$i++;
if ($i % 2) {echo "<div id='listA'>";}else {echo "<div id='listB'>";}
echo "<table width='424' border='0' cellspacing='0' cellpadding='0'><tr><td width='63' valign='top'><div style='text-align:center'><div id='physPhoto'><img src='images/physPhotos/thumbs/".$info['photo']."' width='62' height='67' /></div></div></td><td width='6'></td><td width='290' valign='top'><span class='physName'>".$info['firstName']." ".$info['lastName']."</span><br/><span class='physSpecialty'>".$info['specialty1']." ".$info['specialty2']."</span><br/><span class='physLocation'>".$info['location']."</span></td><td width='65' valign='top'><span class='physLink'>view bio</span></td></tr></table>";
echo "</div><img src='images/oneTrans.gif' width='1' height='4'/>";
}
echo "<br/><br/>";

if ($totalpages > 1)
{
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='http://mydomain/mypage.html?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='http://mydomain/mypage.html.html?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='http://mydomain/mypage.html.html?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='http://mydomain/mypage.html.html?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='http://mydomain/mypage.html?currentpage=$totalpages'>>></a> ";
} // end if
}//end if
echo "<br/><br/>";

}

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.