Начните с преобразования ваших миллисекунд в TimeSpan
:
var time = TimeSpan.FromMilliseconds(milliseconds);
Теперь в .NET 4 вы можете вызвать .ToString()
с аргументом строки формата. См. http://msdn.microsoft.com/en-us/library/system.timespan.tostring.aspx
. В предыдущих версиях .NET вам придется вручную создайте форматированную строку из свойств TimeSpan.
You need to offset your results for the given page you are on in addition to the separate query for getting the count that everyone else has mentioned.
$sql .= "posts p, images im, postimages pi WHERE
i.active = 1
AND pi.post_id = p.id
AND pi.image_id = im.image_id
ORDER BY created_at
LIMIT ". ($page - 1) * $pagesize .", ". $pagesize;
The normal warnings about SQL injection would apply here.
In MySQL
:
SELECT SQL_CALC_FOUND_ROWS
*
FROM posts p, images im, postimages pi
WHERE i.active = 1
AND pi.post_id = p.id
AND pi.image_id = im.image_id
ORDER BY
created_at
LIMIT 16;
SELECT FOUND_ROWS();
The first query will return 16
rows, and the second query will return you the number of rows which would be returned be there no LIMIT
clause in the first query.
You may use it to decide whether to show the "next" link or not.
Выполните отдельный запрос без ограничения, чтобы только возвращал счетчик.
Вы пытаетесь выполнить полную разбивку на страницы или просто установите эту страницу
и следующую страницу
? В последнем случае вы можете просто LIMIT 17
и подсчитать строки результата. Если вы получили 17, вам нужно разбить на страницы.
используйте два запроса, один из которых является вашим, а другой:
SELECT COUNT(primary_key) FROM ... WHERE...