RE: help sorting by a column name
| From: | Rick Emery | Date: | Wed, 03 Apr 2002 22:48:58 +0000 |
| Subject: | RE: help sorting by a column name | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-18175@lists.php.net to get a copy of this message | ||
First, please respond on list.
Second, I know what max does. However, you'll be disappointed in its use
here. This while() will execute ONLY ONCE so a while() construct is of no
use here.
The syntax I sent you is correct. It will select all categories and IDs by
category, then ID in a descending order, per your statement. What you would
do is keep track of which category you are listing. As you read each
record, you would compare the newly-read category to the category you are
currently listing. If the new category is different, you would then create
a new category title.
Another method, would be two selects. The first select would control an
outer loop; this would be the category loop. The inner loop would first
select all reviews for that category and then print out each.
-----Original Message-----
From: Alex Behrens [mailto:bigal@3d-unlimited.com]
Sent: Wednesday, April 03, 2002 4:37 PM
To: Rick Emery
Subject: Re: help sorting by a column name
Oh thats teh statement that gets the number for this statement:
while ($info = mysql_fetch_row($max)) {
printf ("<b><font color='#ffffff'>Hardware Reviews - %s Articles
Total</b></font><br>", $info["0"]);
}
and prints the total number of articles.
however, I dont think the syntax you sent me is write.
this is what I want it to do, but dont know how to program it:
Print $category Review
then print reviews for that category
then Print $category Review (Another category of reviews)
then print reviews for this category
etc, etc.
get what i mean?
Thanks!
--------------------------------------------
-Alex "Big Al" Behrens
E-mail: bigal@3d-unlimited.com
Urgent E-mail: bigal-cell@3d-unlimited.com (Please be brief!)
Phone: 651-482-8779
Cell: 651-329-4187
Fax: 651-482-1391
ICQ: 3969599
Owner of the 3D-Unlimited Network:
http://www.3d-unlimited.com
Send News:
news@3d-unlimited.com
----- Original Message -----
From: "Rick Emery" <remery@excel.com>
To: "'Alex Behrens'" <bigal@3d-unlimited.com>;
<mysql@lists.mysql.com>
Sent: Wednesday, April 03, 2002 4:33 PM
Subject: RE: help sorting by a column name
> $r = mysql_query("SELECT * FROM hwureviews ORDER BY category,num DESC");
>
> what are you trying to do with this statement?:
> while ($info = mysql_fetch_row($max)) {
>
>
>
> -----Original Message-----
> From: Alex Behrens [mailto:bigal@3d-unlimited.com]
> Sent: Wednesday, April 03, 2002 4:08 PM
> To: mysql@lists.mysql.com
> Subject: help sorting by a column name
>
>
> Hey Guys,
>
> I need to reorganize the list of reviews on my site so they are displayed
by
> category. However, I want it to display all the reviews from all
categories
> at once. How do I do this? Here is my syntax now for display all reviews
at
> once, but not sorted by category:
>
> <?php
> $db = mysql_connect( "db32.pair.com", "**********",
> "********");
> mysql_select_db( "net3dual_reviews",$db);
> $r = mysql_query("SELECT * FROM hwureviews ORDER BY num DESC");
> $max = mysql_query("select max(num) from hwureviews",$db);
> while ($info = mysql_fetch_row($max)) {
> printf ("<b><font color='#ffffff'>Hardware Reviews - %s Articles
> Total</b></font><br>", $info["0"]);
> }
> while($a=mysql_fetch_array($r)) {
> printf ("- <a href=\"%s\">%s</a> (Written by: <a
> href=\"mailto:%s\">%s</a>) - [<a
> href='%s' onMouseOver='if (window.event
||
> document.layers) show(\"%s\",event)'
>
onMouseOut='hide(\"%s\")'>Description</a>]<br>",$a["url"],$a["name"],$a["ema
>
> il"],$a["author"],$a["url"],$a["name"],$a["name"]);
> }
> ?>
>
> I want it so it displays them like this:
>
> Processors -
> Reviews listed here
>
> Motherboards
> Reviews listed here
>
> the categories are stored under the column name "category", for reference.
>
> Thanks!
> --------------------------------------------
> -Alex "Big Al" Behrens
> E-mail: bigal@3d-unlimited.com
> Urgent E-mail: bigal-cell@3d-unlimited.com (Please be brief!)
> Phone: 651-482-8779
> Cell: 651-329-4187
> Fax: 651-482-1391
> ICQ: 3969599
> Owner of the 3D-Unlimited Network:
> http://www.3d-unlimited.com
> Send News:
> news@3d-unlimited.com
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
> To request this thread, e-mail <mysql-thread105005@lists.mysql.com>
> To unsubscribe, e-mail
<mysql-unsubscribe-remery=excel.com@lists.mysql.com>
> Trouble unsubscribing? Try:
> http://lists.mysql.com/php/unsubscribe.php
>