Re: [PHP-DB] Sorting the result

2002-02-28 Thread Kristjan Kanarik

On Wed, 27 Feb 2002, William Fong wrote:

 $article_query = mysql_query(select article_name, article_text from
 articles where article_name LIKE '%$q%' ORDER BY $q_count DESC ) or die
 (mysql_error());

 Put the ORDER BY $q_count DESC  in your SQL statement and that will make
  MySQL do the sorting for you.  PHP will get it already sorted.

 Is that what you wanted?

No. The trick is that the variable $q_count will be created during the
mysql_fetch_array process and has a different value for each row of the
result (well, it can have the same, but this doesn't make things easier at
this point). What I'd like to know wheter it is possible to sort the
returned array by $q_count (substr_count($art_text, $q)) or wheter it is
possible to write something like this:

$article_query = mysql_query(select article_name, article_text from
articles where article_text LIKE '%$q%' ORDER BY Q ACCOURANCE IN
article_text DESC) or die (mysql_error());

How to make MySQL to understand this 'Q ACCOURANCE IN article_text' is the
tricky part for me.

Kristjan




 : - Original Message -
 : From: Kristjan Kanarik [EMAIL PROTECTED]
 : To: [EMAIL PROTECTED]
 : Sent: Wednesday, February 27, 2002 2:51 PM
 : Subject: [PHP-DB] Sorting the result
 :
 :
 : : Hi,
 : :
 : : I've come across a problem and I'm affraid that I'm lacking the skills
 of
 : : writing proper SQL queries in order to solve this. I'm building a little
 : : search engine for my site (yes, from scratch! It doesn't have to be the
 : : best, but I think that for my personal use it will be enough) and the
 bit
 : : of code I have right now is as follows:
 : :
 : : snip
 : : /* I'm using MySQL 3.23.37 together with 4.0.6 on a FreeBSD box */
 : :
 : : $article_query = mysql_query(select article_name, article_text from
 : articles where article_name LIKE '%$q%') or die (mysql_error());
 : : /* where $q is the search query with a space added in front */
 : :
 : : while ($results = mysql_fetch_array($article_query)) {
 : :  $art_name = $results[article_name];
 : :  $article_text = $results[article_text];
 : :  $q_count = substr_count($article_text, $q);
 : :  echo b$art_name/bp$article_textp;
 : : }
 : :
 : : /snap
 : :
 : : But what I'd like to achieve is that the results would be displayed in a
 : : way ORDER BY $q_count DESC - the entry with most $q_count would be
 : : displayed first, next one second etc. I'm sure that there is a way to
 sort
 : : the array with PHP, but is it also possible to let the MySQL do the job?
 : : It would save some CPU power I think... if not, what would be the
 easiest
 : : way to do it with PHP?
 : :
 : : TIA,
 : : Kristjan
 : :
 : : P.S. Please CC me as well, I am only on the digest.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Sorting the result

2002-02-27 Thread William Fong

 $article_query = mysql_query(select article_name, article_text from
articles where article_name LIKE '%$q%' ORDER BY $q_count DESC ) or die
(mysql_error());

Put the ORDER BY $q_count DESC  in your SQL statement and that will make
MySQL do the sorting for you.  PHP will get it already sorted.

Is that what you wanted?

-w


--
William Fong - [EMAIL PROTECTED]
Phone: 626.968.6424 x210  |  Fax: 626.968.6877
Wireless #: 805.490.7732|  Wireless E-mail: [EMAIL PROTECTED]




- Original Message -
From: Kristjan Kanarik [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, February 27, 2002 2:51 PM
Subject: [PHP-DB] Sorting the result


: Hi,
:
: I've come across a problem and I'm affraid that I'm lacking the skills of
: writing proper SQL queries in order to solve this. I'm building a little
: search engine for my site (yes, from scratch! It doesn't have to be the
: best, but I think that for my personal use it will be enough) and the bit
: of code I have right now is as follows:
:
: snip
: /* I'm using MySQL 3.23.37 together with 4.0.6 on a FreeBSD box */
:
: $article_query = mysql_query(select article_name, article_text from
articles where article_name LIKE '%$q%') or die (mysql_error());
: /* where $q is the search query with a space added in front */
:
: while ($results = mysql_fetch_array($article_query)) {
:  $art_name = $results[article_name];
:  $article_text = $results[article_text];
:  $q_count = substr_count($article_text, $q);
:  echo b$art_name/bp$article_textp;
: }
:
: /snap
:
: But what I'd like to achieve is that the results would be displayed in a
: way ORDER BY $q_count DESC - the entry with most $q_count would be
: displayed first, next one second etc. I'm sure that there is a way to sort
: the array with PHP, but is it also possible to let the MySQL do the job?
: It would save some CPU power I think... if not, what would be the easiest
: way to do it with PHP?
:
: TIA,
: Kristjan
:
: P.S. Please CC me as well, I am only on the digest.
:
:
: --
: PHP Database Mailing List (http://www.php.net/)
: To unsubscribe, visit: http://www.php.net/unsub.php
:



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php