Jump to content

[SOLVED] Displaying records of current day


nashsaint

Recommended Posts

Hi,

 

I created a code that will display records of the day, with pagination.  The problem is that the result displays all the records in 1 page, though I set the display limit to 10, but pagination displays more pagenumbers and shows same entries when numberings are clicked.

 

Here's my code for the count:

    
$display = 10;  
$curday = date("Y-m-d");


$query = "SELECT count(*) FROM job_log WHERE date_added ='$curday' ORDER BY eng_name";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];

// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
	$num_pages = ceil ($num_records/$display);
    } elseif ($row[0] == 0) {

        echo ' <center>There are currently no entries</center> ';
        include ('../../includes/footerSingle.html');
        exit();

} else {
	$num_pages = 1;
}

 

 

Here's my code to query and display records:

// Make the query.
$fcurd = date("Y-m-d");
$query = "SELECT date_added, eng_name, job_no, diagnosis FROM job_log WHERE date_added ='$curday' ORDER BY eng_name";
$result = @mysql_query ($query); // Run the query.

// Table header.

echo '<div id="display_livejobs"></div>';
echo '<table align="center" class="tableQueryList">
<tr>
    <th class="head" align="center"><b>No.</b></th>
<th class="head" align="center"><b>Name</b></th>
<th class="head" align="left"><b>Job Number</b></th>
    <th class="head" align="left"><b>Diagnostic</b></th>
</tr>
';


$count = 0;
while ($drow = mysql_fetch_array($result, MYSQL_ASSOC)) {
        switch (true) {
        default: $bg = '#ffffff';
    }

echo '
        <tr bgcolor="' . $bg . '">
        <td align="center">'. $count ++ .'</td>
        <td align="left">' . $drow['eng_name'] . '</td>
        <td align="left">' . $drow['job_no'] . '</td>
	<td align="left">' . $drow['diagnosis'] . '</td>';
    }
    echo '</table>';

 

 

and here's the pagination:

if ($num_pages > 1) {

echo '<br /><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;

// If it's not the first page, make a Previous button.
if ($current_page != 1) {
	echo '<a href="index.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> ';
}

// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
	if ($i != $current_page) {
		echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' .  $i . '</a> ';
	} else {
		echo $i . ' ';
	}
}

// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
	echo '<a href="index.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>';
}

echo '</p>';

} // End of links section.

 

Hope you can help.. many thanks.

Maybe I'm missing it, but I don't see anywhere in there that you limit the query...

 

Generally when paginating, you will query the database for all records and set the LIMIT to the desired number on the query...

 

Then on the next page, you rerun the query and start the limit at the 11th record and show 10 more etc.

 

for example, the first query would be something like

 

SELECT * FROM `your_table` LIMIT 0, 10

 

Then the query on page two would be run with

 

SELECT * FROM `your_table` LIMIT 11, 20

 

Hope that helps

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.