Новости
Документация
Download
Webboard
Поиск
FAQ/ЧаВо
Обратная связь




MySQL.RU - Webboard



Вернуться
количество записей предыдущего запроса (sdr) 05/08/2006 - 07:47:04
      Re: количество записей предыдущего запроса (bac) 05/08/2006 - 09:38:36
      Re: sorry! (bac) 05/08/2006 - 09:40:15
      Re: sorry! (sdr) 05/08/2006 - 10:18:13
      Re: Нет не то (bac) 05/08/2006 - 15:47:42
      Re: А может вот это? ;) (Dinky) 06/08/2006 - 06:33:52
      Re: количество записей предыдущего запроса (DiGiTAL) 07/08/2006 - 16:19:32

> Original message text:
> From: sdr - 05/08/2006 - 07:47:04
> Subject:количество записей предыдущего запроса
> -----------------
> Есть некий запрос в php
> $sql_count = "SELECT DISTINCT * FROM disccart WHERE $recvizit LIKE '$letter[3]%' ORDER BY '$recvizit' ASC";
> $cou=mysql_query($sql_count);
> Как сделать еще одни к mysql, который бы посчитал количество строк полученных из предыдущего запроса. Пробую делать так
> $sql_count = "SELECT DISTINCT * FROM disccart WHERE $recvizit LIKE '$letter[3]%' ORDER BY '$recvizit' ASC";
> $cou=mysql_query($sql_count);
> $sql_count2 = "SELECT count($cou) * FROM disccart WHERE $recvizit LIKE '$letter[3]%' ORDER BY '$recvizit' ASC";
> $cou=mysql_query($sql_count2);
> print($cou);
> не получается. Подскажите, как правильно сделать?
>


From: Dinky - 06/08/2006 - 06:33:52
Subject:А может вот это? ;)
-----------------
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html
FOUND_ROWS()

A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
-> WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();
The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause. (If the preceding SELECT statement does not include the SQL_CALC_FOUND_ROWS option, then FOUND_ROWS() may return a different result when LIMIT is used than when it is not.)

The row count available through FOUND_ROWS() is transient and not intended to be available past the statement following the SELECT SQL_CALC_FOUND_ROWS statement. If you need to refer to the value later, save it:

mysql> SELECT SQL_CALC_FOUND_ROWS * FROM ... ;
mysql> SET @rows = FOUND_ROWS();
If you are using SELECT SQL_CALC_FOUND_ROWS, MySQL must calculate how many rows are in the full result set. However, this is faster than running the query again without LIMIT, because the result set need not be sent to the client.

SQL_CALC_FOUND_ROWS and FOUND_ROWS() can be useful in situations when you want to restrict the number of rows that a query returns, but also determine the number of rows in the full result set without running the query again. An example is a Web script that presents a paged display containing links to the pages that show other sections of a search result. Using FOUND_ROWS() allows you to determine how many other pages are needed for the rest of the result.

The use of SQL_CALC_FOUND_ROWS and FOUND_ROWS() is more complex for UNION statements than for simple SELECT statements, because LIMIT may occur at multiple places in a UNION. It may be applied to individual SELECT statements in the UNION, or global to the UNION result as a whole.

The intent of SQL_CALC_FOUND_ROWS for UNION is that it should return the row count that would be returned without a global LIMIT. The conditions for use of SQL_CALC_FOUND_ROWS with UNION are:

The SQL_CALC_FOUND_ROWS keyword must appear in the first SELECT of the UNION.

The value of FOUND_ROWS() is exact only if UNION ALL is used. If UNION without ALL is used, duplicate removal occurs and the value of FOUND_ROWS() is only approximate.

If no LIMIT is present in the UNION, SQL_CALC_FOUND_ROWS is ignored and returns the number of rows in the temporary table that is created to process the UNION.

--
Dmitry


[Это сообщение - спам!]

Последние сообщения из форума

Уважаемые посетители форума MySQL.RU!
Убедительная просьба, прежде чем задавать свой вопрос в этом форуме, обратите внимание на разделы:
- ответы на наиболее часто задаваемые вопросы - FAQ
- раздел документация
- раздел поиск по сообщениям форума и документации
Также, старайтесь наиболее подробно указывать свою ситуацию (версию операционной системы, версию MySQL, версию программного обеспечения, по которому возникает вопрос, текст возникающих ошибок, и др.)
Помните, чем конкретнее Вы опишете ситуацию, тем больше шансов получить реальную помощь.
 Имя:
 E-mail:
 Тема:
 Текст:
Код подтверждения отправки: Code
29393



РЕКЛАМА НА САЙТЕ
  Создание сайтов | |