I am a newbie at php. I am experienced in ASP and ASP.net, but this is my first time on php.
I have a site that is using a mysql database. I have everything working, except that I seem to be fetching two rows at a time, or at least every other row. The first time I do a fetch, it is outside of the do loop. It works fine. Then I enter the do loop, and I get every other record.
When I run the following code, I get every other row after the first one. If I am looking for ten verses, I will get verse 1, 2, 4, 6, 8, 10. I know that the database has the verses in it, because if I look for verse 2-11, I will get 2,3,5,7,9,11. I can find no reason for this.
//Open bible table
$sSQL="SELECT ID, Book, BookNo, Chapter, VerseNo, VerseText FROM KJV ORDER BY ID;";
$result=mysql_query($sSQL);
//Move to start reference
//Get the start book.
do {
$row=mysql_fetch_array($result);
}
while($row['BookNo']!=$startbookno);
//Get the start chapter.
while($row['Chapter']!=$startchap)
{
$row=mysql_fetch_array($result);
}
if ($row['Chapter']!=$startchap)
{
mysql_free_result($result);
print "That chapter does not exist.<br>"."\r\n";
return $function_ret;
}
//Get the start verse.
while($row['VerseNo']!=$startverse)
{
$row=mysql_fetch_array($result);
}
if ($row['VerseNo']!=$startverse)
{
mysql_free_result($result);
print "That verse does not exist.<br>"."\r\n";
return $function_ret;
}
$flag=false;
$bflag=false;
$lastbookno=0;
$exitflag=false;
do
{
if ($row["BookNo"]>$lastbookno)
{
printf('<div class="book">%s</div>',$row["Book"]);
$lastbookno=$row["BookNo"];
$lastchapter=0;
$flag=false;
}
if ($row["Chapter"]>$lastchapter)
{
if ($row["Book"]=="Psalms")
{
print '<div class="chapter">Psalm '.$row["Chapter"].'</div>';
}
else
{
print '<div class="chapter">Chapter '.$row["Chapter"].'</div>';
}
$lastchapter=$row["Chapter"];
}
print '<div class="verseno">'.$row["VerseNo"].'</div>';
print '<div class="verse">'.$row["VerseText"].'</div>';
printf (" ID before fetch=%s<br/>",$row["ID"]);
$row=mysql_fetch_array($result);
printf (" ID after fetch=%s<br/>",$row["ID"]);
if (EndOfRef($result))
{$endflag=true; //Not at end of recordset
print "End of Ref";}
if ($row["BookNo"]>intval($endbookno)) {$endflag=true; //Current book number does not exceed the end book number
printf ("BookNo=%s endbookno=%s",$row["BookNo"],$endbookno);}
if (($row["BookNo"]==intval($endbookno)) && //Current book = last book no and
($row["Chapter"]>intval($endchap))) {$endflag=true; //Current chapter does not exceed end chapter number.
printf ("BookNo=%s endbookno=%s Chapter=%s endchap=%s",$row["BookNo"],$endbookno,$row["Chapter"],$endchap);}
if (($row["BookNo"]==intval($endbookno)) && ($row["Chapter"]==intval($endchap)) && ($row["VerseNo"]>intval($endverse)))
{$endflag=true;
printf ("<br/>BookNo=%s endbookno=%s Chapter=%s endchap=%s VerseNo=%s endverse=%s ID=%s",$row["BookNo"],$endbookno,$row["Chapter"],$endchap,$row["VerseNo"],$endverse,$row["ID"]);}
} while (!$endflag);
mysql_free_result($result);
I know that you experts out there can write the code much more efficiently than what I have, but right now, I don't need efficiency. I need it to work. Any help will be appreciated. Comments on my code will also be appreciated, as I try to learn this new language, but I need concentration on my problem.