-1

Here is my mysql table

mysql table

Both Happy and Sad are INT and whenever one is chosen it puts a 1 into their column and nothing the in the other one.

I want to figure out either which row has had more entires (every time that option is chosen it adds a 1 to that row and nothing to the other) or at the very least how many entries have been to one of them (I just need to know if there are more sad's than happy's at the end of a month).

I have tried this code

if ($result = $mysqli->query("SELECT Negative FROM tablename")) {

/* determine number of rows result set */
$row_cnt = $result->num_rows;

printf("Result set has %d rows.\n", $row_cnt);

however this gives the error "expects parameter 1 to be resource boolean given"

Also tried mysql_numrows however it came up with the same error. Any idea how I could achieve this?

Sahil Manchal
  • 464
  • 6
  • 19

2 Answers2

1

Apart the fact that your table structure is quite weird, you can achieve the count of sad and happy days with the following query:

select sum(Happy) as HappyCount, sum(Sad) as SadCount from tablename

But even with this, I'm not even sure of what are you atrying to achieve.

kitensei
  • 2,440
  • 2
  • 37
  • 66
  • Basically the count is representing how many days they have been sad and how many they have been happy throughout the month, and if the number of days they have been sad is greater than happy it is supposed to echo something to the user. – Rameez Mahmood Feb 29 '16 at 11:19
  • and why do you have some values empty, some at 0 and some at 1, what's the point ? – kitensei Feb 29 '16 at 11:43
  • The 0s aren't supposed to be there, they came after I changed the format of the table, it is supposed to be 1 for whichever option is chosen each day and nothing for the other one. I'll empty the contents of the table and re-enter the contents with just 1's and blanks if that helps – Rameez Mahmood Feb 29 '16 at 11:52
  • no need, you can use the query I gave you, that will work – kitensei Feb 29 '16 at 12:09
0

mysqli_num_rows:

Return Values

Returns TRUE on success or FALSE on failure. For SELECT, SHOW, DESCRIBE or EXPLAIN mysqli_query() will return a result object.
Ghostman
  • 5,918
  • 9
  • 33
  • 52