fwilson Posted March 3, 2013 Share Posted March 3, 2013 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 gjest2I 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 -best moonunit Quote Link to comment https://forums.phpfreaks.com/topic/275174-counting-rows-in-table/ Share on other sites More sharing options...
teynon Posted March 3, 2013 Share Posted March 3, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275174-counting-rows-in-table/#findComment-1416190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.