Hi there,
I have a small question:
I have a table with lots of rows in it. Of course all have a different id,
but each can be assigned to a certain category. Categories correspond
with 1 - 10.
So a row looks like this: 'unique id | 4'
What i want is to do a count how much rows belong to a certain category.
Is it possible to do the following (from 1 query)
echo $counted_rows['4'];
Which sould return the number of rows with category '4';
Or is there anything similar if this is wrong?
Any help is great!! :) 6 4400
To get the number of rows with a category '4' use:
SELECT COUNT( * ) FROM `table` WHERE category = '4';
To get the row count for all categories in a single query (I think what
you're asking for):
SELECT COUNT( category ) AS repetitions, category FROM `table`
GROUP BY category
- Kevin
"knoak" <kn******@hotma il.com> wrote in message
news:a5******** *************** ***@posting.goo gle.com... Hi there,
I have a small question: I have a table with lots of rows in it. Of course all have a different id, but each can be assigned to a certain category. Categories correspond with 1 - 10.
So a row looks like this: 'unique id | 4'
What i want is to do a count how much rows belong to a certain category. Is it possible to do the following (from 1 query)
echo $counted_rows['4'];
Which sould return the number of rows with category '4';
Or is there anything similar if this is wrong?
Any help is great!! :)
Well, to begin: Thank you for helping. :D
Ehm i know i am not asking for the first, because this would force me
to run the query for each category.
Could you please explain a little bit more about the second one? I can't seem
to get it to work... :( :s
Thanks again
"Kevin" <ke***@wxREMOVE 4SPAM3.com> wrote in message news:<L8******* *************@c omcast.com>... To get the number of rows with a category '4' use:
SELECT COUNT( * ) FROM `table` WHERE category = '4';
To get the row count for all categories in a single query (I think what you're asking for):
SELECT COUNT( category ) AS repetitions, category FROM `table` GROUP BY category
- Kevin
"knoak" <kn******@hotma il.com> wrote in message news:a5******** *************** ***@posting.goo gle.com... Hi there,
I have a small question: I have a table with lots of rows in it. Of course all have a different id, but each can be assigned to a certain category. Categories correspond with 1 - 10.
So a row looks like this: 'unique id | 4'
What i want is to do a count how much rows belong to a certain category. Is it possible to do the following (from 1 query)
echo $counted_rows['4'];
Which sould return the number of rows with category '4';
Or is there anything similar if this is wrong?
Any help is great!! :)
What problem are you having? Obviously you need to replace the field and
table names with the ones from your table.
"knoak" <kn******@hotma il.com> wrote in message
news:a5******** *************** ***@posting.goo gle.com... Well, to begin: Thank you for helping. :D
Ehm i know i am not asking for the first, because this would force me to run the query for each category.
Could you please explain a little bit more about the second one? I can't seem to get it to work... :( :s
Thanks again "Kevin" <ke***@wxREMOVE 4SPAM3.com> wrote in message news:<L8******* *************@c omcast.com>... To get the number of rows with a category '4' use:
SELECT COUNT( * ) FROM `table` WHERE category = '4';
To get the row count for all categories in a single query (I think what you're asking for):
SELECT COUNT( category ) AS repetitions, category FROM `table` GROUP BY category
- Kevin
"knoak" <kn******@hotma il.com> wrote in message news:a5******** *************** ***@posting.goo gle.com... > Hi there, > > I have a small question: > I have a table with lots of rows in it. Of course all have a different > id, > but each can be assigned to a certain category. Categories correspond > with 1 - 10. > > So a row looks like this: 'unique id | 4' > > What i want is to do a count how much rows belong to a certain > category. > Is it possible to do the following (from 1 query) > > echo $counted_rows['4']; > > Which sould return the number of rows with category '4'; > > Or is there anything similar if this is wrong? > > Any help is great!! :)
Yes thanks, that far i got, but how can i call the values in different parts
of the page, whereever i want.
So for instance i have 10 tables and in the first one i call $counted_rows_4
or so, and in the next one $counted_rows_9 . So they correspond with the
category. It doesnt matter how i call them, as long as i can call them
individually.
Hope you get it, and sorry for me being a noob. I googled on this, searched the
mysql site, but couldn't find anything that makes sense to me.
Thanks again.
"Kevin" <ke***@wxREMOVE 4SPAM3.com> wrote in message news:<w4******* *************@c omcast.com>... What problem are you having? Obviously you need to replace the field and table names with the ones from your table.
"knoak" <kn******@hotma il.com> wrote in message news:a5******** *************** ***@posting.goo gle.com... Well, to begin: Thank you for helping. :D
Ehm i know i am not asking for the first, because this would force me to run the query for each category.
Could you please explain a little bit more about the second one? I can't seem to get it to work... :( :s
Thanks again "Kevin" <ke***@wxREMOVE 4SPAM3.com> wrote in message news:<L8******* *************@c omcast.com>... To get the number of rows with a category '4' use:
SELECT COUNT( * ) FROM `table` WHERE category = '4';
To get the row count for all categories in a single query (I think what you're asking for):
SELECT COUNT( category ) AS repetitions, category FROM `table` GROUP BY category
- Kevin
"knoak" <kn******@hotma il.com> wrote in message news:a5******** *************** ***@posting.goo gle.com... > Hi there, > > I have a small question: > I have a table with lots of rows in it. Of course all have a different > id, > but each can be assigned to a certain category. Categories correspond > with 1 - 10. > > So a row looks like this: 'unique id | 4' > > What i want is to do a count how much rows belong to a certain > category. > Is it possible to do the following (from 1 query) > > echo $counted_rows['4']; > > Which sould return the number of rows with category '4'; > > Or is there anything similar if this is wrong? > > Any help is great!! :)
Hi
I finally discover the way how to get what I need
Let's look to my code
----------------------- CODE ------------------------
$res = @mysql_query("S ELECT COUNT(*) AS ToT FROM table_name");
$dato = mysql_fetch_arr ay($res)
echo($dato[ToT])
----------------------- CODE ------------------------
With this code you will get how much records do you have in DB
PS
Whan you think that everything is over and that you are at bottom o
trying push harder to see what is under
Auro http://eye.cc -php- web design
This gives you the record count for a single TABLE, not the entire DATABASE.
Learn to use the correct terminology.
--
Tony Marston http://www.tonymarston.net
"auron" <ma***@compriov endi-dot-com.no-spam.invalid> wrote in message
news:kX******** ***********@new s.sisna.com... Hi, I finally discover the way how to get what I need.
Let's look to my code:
----------------------- CODE ------------------------>
$res = @mysql_query("S ELECT COUNT(*) AS ToT FROM table_name"); $dato = mysql_fetch_arr ay($res);
echo($dato[ToT]); ----------------------- CODE ------------------------>
With this code you will get how much records do you have in DB.
PS: Whan you think that everything is over and that you are at bottom of trying push harder to see what is under.
Auron http://eye.cc -php- web design This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Xizor |
last post by:
Ok, I'm new to PHP and MySQL. I've been going through tutorials, reading the
documentation, and looking through web sites. PHP to me seems great! With
MySQL it seems even better.
However, I'm an experienced C++ programmer. This has allowed me to see many
potential areas where the security of a server can be compromised through
loopholes in PHP. Granted, with the right knowledge these potential threats
can be avoided. But I've just...
|
by: marko2 |
last post by:
I have debian running and this is how I have it setup
# ls -ld /var/lib/mysql
drwxr-xr-x 4 mysql mysql 4096 Aug 19 11:29 /var/lib/mysql
I was shown how to setup a password for user mysql here
http://dle.ascendant.ca/restoring-mysql-root-HOWTO.txt,
because at one time all I would have to do it hit enter after
# mysql -h localhost -p -u mysql
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest version of this document can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
|
by: dottty |
last post by:
Hi,
i have a table that has the following fields:
id, name, dept, pay
1, John, Sales, 4000
2, Peter, HR, 5000
etc.
How do i count how many people there are in each dept with an sql query?
I find this surprisingly difficult, given the fact that i can sum the total
|
by: NewbieSupreme |
last post by:
I installed Apache 2.0.58, tested it, got the "working" page. Installed
MySQL 5.0.22, and didn't really see how to test that, but there is a mysql
process running in the task manager. Ran through the PHP 5.1.4 installation
directions, and that seems to work, since I can use phpinfo() and get all
the information on a test php page.
Then I installed (really just unzipped and placed some files according to
the directions) PHPMyAdmin; did...
| |
by: Garry |
last post by:
How do I cycle through a MySQL query result one row at a time so that I can
do some work on each individual row, instead of having the whole query
scroll by. I need to have the ability to post each row to a form and then
work on it, posting the results, then go on to the next row.
Thank You in Advance for your putting me on the right track.
|
by: ojorus |
last post by:
Hi!
My company make several flash-based games, and I use php to communicate with
mysql to provide highscore-lists.
My problem is this:
When I save a player's score in the mysql-table, I want to find which place
the player got with his score (today). To get this I have tried two
different solutions, which both works, but are very ineffective: (The
Time-field is a DateTime type, and I have Score and Time as Indexes)
|
by: Martien van Wanrooij |
last post by:
I have been using for a while a class to create photo albums. Shortly, an
array of photo's is declared, initially they are shown as thumbnails, by
clicking on a thumbnail a larger photo is shown and there are links to the
thumbnail list but also to the previous and next photo as the function
remembers which position the photo has got in the array.
Now I tried to do the same thing by retrieving photos from a mysql database
(which is much...
|
by: Paks |
last post by:
Hello,
I have a quick little question about the MySQL-command LEFT(columnName,int).
My question is if there's a counterpart in PostgreSQL for this command and what it is?
What I want to do is take the first specified amount of signs in a text-column and print them out.
For example:
Instead of printing out all information in a text-column...
SELECT story FROM table01;
Once upon a time in a land far far away lorem ipsum dolor sit amet,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |