Jump to content

count the number of multiple showing variable in a column


Ryflex

Recommended Posts

I mean a single column with about 20 records (will be more later on) and it is standard filled with all 0's.

When 1 of the rows has a 1 in it it means that row is busy upgrading and the rest should not be able to.

That's why I need to have something that tells me if there's a 1 in the column.

Thnx for looking in to it

Ryflex

Link to comment
Share on other sites

for example... say you have named the rows... or if this in array just basically make sure you add and total up the rows/columns you want to get the total of.

 

Pretty simple.

 

I.E: row 1's name is andy

row 2's name is bill.

 

both have 1 in each.

 

say for example:

 

<?php

 

$bill = ['bill'];

$andy = ['andy'];

$total = $andy+$bill;

 

echo '$total';

 

?>

 

something like that

Link to comment
Share on other sites

building

finish

upgrading

house

1284944810

1

shed

0

0

mall

0

0

 

In my code it says when the time now exceeds the finish in the table set it 0 and set upgrading 0.

While house is upgrading the other 2 shouldn't be able to.

What I need is a simple SELECT that gives me how much 1's there are (because later on it will be possible to upgrade 2 at a time.

Thnx again

Ryflex

Link to comment
Share on other sites

@ MrAdam

 

I tried the following but still it upgrades when it's supossed not to.

$count_query                = "Select count(upgrading)
                               From buildings
                               Where upgrading = '1'";
$count_upgrading            = mysql_query($count_query);

//               Data CHECK
if($count_upgrading > '0')

Thnx

Ryflex

Link to comment
Share on other sites

@ MrAdam

 

$count_query                = "Select count(upgrading)
                               From buildings
                               Where upgrading = '1'";
$count_mysql            = mysql_query($count_query);
$count_array            = mysql_fetch_array($count_mysql);
$count_upgrading        = $count_array['count'];

 

Sorry just starting so still trying to find shortcuts where there aren't any.

This better???

Because now I'm not able to upgrade anything anymore....

Thnx Ryflex

Link to comment
Share on other sites

 

......

Because now I'm not able to upgrade anything anymore....

Thnx Ryflex

 

better if you post most of the code than you have... you last sentence is telling that you have more code that is been affected for what you are showing... without knowing/seeing the rest of the code is impossible to know what is happening in reality

Link to comment
Share on other sites

If you want to reference the result of count(upgrading) as $count_array['count'], you would need to use an alias name count in the query -

 

Select count(upgrading) as count

 

If you were developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON, you would be getting an undefined error message when referencing $count_array['count'].

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.