PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 7th, 1999, 08:50 AM
kumars
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I have a mySQL table items. With Category, Product, Description and Price. I have to find all the category and list them using PHP in my web page (pricelane.tzo.com)

Say I have 10 Electronics and 3 Computers and 6 Software, the list should only say Electronics(10) and Computers(3) and Software(6).

Is there any PHP-MYSQL function to cut this?

Appreciate any help

Kumars
www.pricelane.com

Reply With Quote
  #2  
Old September 7th, 1999, 02:18 PM
kumars
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
well I have figured (it is not that difficult) out a way:

Here is my code:
<body bgcolor=YELLOW>
<h1>Item Index</h1>
<?
mysql_connect("localhost", "userid", "");
$query = "SELECT category FROM items ORDER BY category";
$result = mysql_db_query("mydatabase", $query);
if($result) {
$number = mysql_numrows($result);
echo "Item Index: ($number) <ul>";
$j = 0;
$icat = "";
WHILE ($j < $number){

$category = mysql_result($result,$j,"category");
if ($j == 0){
//if it is the first item set icat value
$icat = $category;
//depending on the keyword clicked the correspondig page will be opened, at this moment this is not complete and need some work here
echo "<li><A href='$category.php3'>$category</A>";
}elseif ($category <> $icat){ //icat value has changed
$icat = $category; //again set icat value
echo "<li><A href='$category.php3'>$category</A>"; //display as a href link
}
$j++; //increment the value.
}
echo "</ul>";
} else {
echo "No data."; //if not data
}
mysql_free_result($result); //clear the array

?>
..some footer code here
</body>

Reply With Quote
  #3  
Old September 7th, 1999, 04:20 PM
scollo
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Hi Kumars,

I didn't take the time to read all of your code (sorry), so I may have misinterpreted what you are trying to do, but you may be able to save some time with MySQL's count() function:

http://www.mysql.com/Manual_chapter/manual_Reference.html#Functions

--Christopher

Reply With Quote
  #4  
Old September 9th, 1999, 09:12 PM
kumars
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thank you. GROUP BY is what exactly I wanted to use. I just did the whole script with one line here is the command
$query = "select category from items GROUP BY
category";
WOW! it is neat.

Thank you Christopher for pointing the direction.

kumars
pricelane.tzo.com (future www.pricelane.com)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > How can I categorize mySQL table and

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap