There’s a .txt file with 18 lines in it. Each line has a bunch of data about a particular book (title, author, isbn, etc…) that separates these attributes with an asterisk “*”. The php page is reading from that file, extracting the data on the line (via explode), seeing if the keyword (from another page) matches the title of any of the books and printing the results. Or it should be anyway.
I can get it to display all the books if there is a blank keyword (this is set to ‘ALL’). But if there IS a keyword entered, it only reads the first line in the .txt file…this leads me to believe that I did something wrong in my loop.
I’ve spent several hours trying to figure out what it is I’m doing wrong here. I just can’t get it. Any help with an explanation as to what I did wrong or what I needed to do, would be greatly appreciated. I don’t want a copy/pasted solution, I want to learn from the mistake and understand. Here’s the code:
[php] if ($keyword === ‘ALL’)
{
for ($ii = 1; $ii <= $lines_in_file; $ii++)
{
print “
” . $ii . ". " . $title;
print “
” . "Category: " . $category;
print “
” . "Publication Date: " . $pub_date;
print “
” . "ISBN: " . $isbn . “
}
}
else
{
for ($ii = 1; $ii <= $lines_in_file; $ii++)
{
$pos = stripos($title, $keyword);
if ($pos === false)
{
print "<br />There are no matches found for " . "'" . $keyword . "'";
break;
} elseif ($post !== false)
{
print "<p>" . $ii . ". " . $title;
print "<br />" . "Category: " . $category;
print "<br />" . "Publication Date: " . $pub_date;
print "<br />" . "ISBN: " . $isbn . "</p>";
} [/php]
Where did I go wrong?