Jump to content

Recommended Posts

Hello...

I have a .txt database with ~100 records.  I only want to show the 15 records that are at the top (referring to reading order of the file).

Here is my php code to display the records.

http://www.flcbranson.org/mobile.php?content=mobile-freedownloads.php if you want to see the results of the code, below.

<?php
$index_file = 'services/series/Index-Date.txt';
$fd = fopen($index_file, 'r');
if ($fd) {
        while (!feof ($fd)) {
                $seriestitle = trim(fgets($fd, 1024)); // Series Title
                if(feof ($fd))
                break;
                $seriessubtitle = trim(fgets($fd, 1024)); // Series subtitle
                $seriesinfo  = trim(fgets($fd, 1024)); // Series Info (Church name)
                $serieslocation = trim(fgets($fd, 1024)); // City, State
                $seriesindex = trim(fgets($fd, 1024)); // Series index file
                $seriesstatus = trim(fgets($fd, 1024)); //Online Only?
                $divider     = trim(fgets($fd, 1024)); // Divider
                $seriestitle2 = $seriestitle;
                $seriestitle3 = str_replace("'", "%27", $seriestitle); // Kind of makes the alt= below work "God's Will" ends up being "God%27s Will" but without is "God"
                if(strstr($seriestitle,"<")) {
                        $seriestitle2 = strip_tags($seriestitle);
                }
                $seriestitle2 = urlencode($seriestitle2);
                if(file_exists("images/ProductCovers/".substr($seriesindex,0,-4).".jpg")) {
                        echo "<img src='images/ProductCovers/".substr($seriesindex,0,-4).".jpg' width='115' height='150' border='0' alt='".substr($seriestitle3,7)."'><br />";
                }
        }
        fclose ($fd);
}
?>

I'm assuming that "for" would do the trick, but when I tried I got 10 copies of every record.

Hehehe...

I'm guessing that it's a quick fix.

Thanks...

JJ

Link to comment
https://forums.phpfreaks.com/topic/227679-show-top-15-database-entries/
Share on other sites

Change this

if ($fd) {
        while (!feof ($fd)) {
                $seriestitle = trim(fgets($fd, 1024)); // Series Title

 

To this

if ($fd) {
        $maxCount = 10; //Set to number of records to display
        $count = 0;
        while (!feof ($fd) && $count<$maxCount) {
                $count++;
                $seriestitle = trim(fgets($fd, 1024)); // Series Title

  • 1 month later...

Bah...

You with your fancy databases.

I'll have to look into that.

Unfortunately, it will probably mean that I will have to do all the maintenance, whereas multiple people maintain their own .txt files.

I was hoping that it would be something simple like...

if (%i >15 && >30) echo "";

elseif (%i >30 && <45) echo "";

etc...

JJ

If you want to use txt files you could very easily run into performance issue. On every page load you would have to read the entire txt file to be able to determine the number of pages and to get the content for the current page. And, you could use a database and build an interface for users to modify their own data.

 

If I get some time this afternoon, I'll throw some code together for you to get started with what you have.

On every page load you would have to read the entire txt file to be able to determine the number of pages

Unless of course you stored all that data in a SESSION, which probably isn't the wisest choice, but it would do the trick.

 

That's what SMF (the forum software used here) does... although they have databases... they store the most relevant information in a SESSION variable.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.