Jump to content

Counting rows in table


fwilson

Recommended Posts

Hi!

I've made a website for our wedding and let me tell you, it's been a looong time since I did any programing in PHP and mysql.

I actually managed to make a decent HTML5 page with some php elements a mysql DB that registers all the guests who sign up and even sends a confirmation per e-mail and sms.

Now I'm working on the back-end where we can view all the guests who has signed up, which also works just fine.

I have now however, arrived at the point where my mySQL skills come to an abrupt stop.

The database is called bryllup and the only table I'm using is called deltager.

I have two rows which I want to count, these rows are called, gjest1 and gjest2

I need to make a php script that checks if gjest1 and gjest2 IS NOT NULL (i guess) and then count and add then into one variable and then print them.. something like:

print "So far there are $row guests registered for the big day";

Anyone able to help us out with this?

Cheers, will make the musses very happy smile.gif

-

best moonunit

Link to comment
https://forums.phpfreaks.com/topic/275174-counting-rows-in-table/
Share on other sites

WIthout looking at your table, you could probably do this with two queries.

 

1) SELECT count(*) FROM deltager WHERE gjest1 IS NOT NULL

 

2) SELECT COUNT(*) FROM deltager WHERE gjest2 IS NOT NULL

 

You could join them together into a single query as well.

SELECT count(*) AS count1, (SELECT count(*) FROM deltager WHERE gjest2 IS NOT NULL) AS count2 FROM deltager WHERE gjest1 IS NOT NULL

 

You could also use a union and return the results on separate rows. I don't know what your database looks like though. If you have numerical values and you litterally want a total of the numbers in those rows, you could use sum in a simplified query

 

SELECT sum(gjest1), sum(gjest2) FROM deltager

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.