Jump to content

Recommended Posts

i have a table (cfsCustomersImages)

 

containing the columns

 

imagesID

image

custID

imageWant

 

the value of column imageWant is default "N" if the user wants and image they have a form they can check to change the value to "Y"

 

what i need to show is a value of the total of "Y" values in the column

 

for example 

 

if 6 "Y"'s are in the columns

 

6 images have been selected

 

does this make sense?

Link to comment
https://forums.phpfreaks.com/topic/279960-show-a-total-based-on-a-column-value/
Share on other sites

In this case you need to use MySQL COUNT function (I assume your RDMS is mysql).

 

The COUNT function returns the number of rows in a table. The COUNT function allows you to count all rows in a table or rows that match a particular condition.

 

So now your query should be something like this. 

SELECT COUNT(*)
FROM cfsCustomersImages
WHERE imageWant = 'Y'

What you are looking for, THIS IS SQL FIDDLE

Edited by thara

hi, thanks for you response

 

i have tried your suggestion but and not getting the results. i have put in my workings

$colname_rsCustomer = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsCustomer = $_SESSION['MM_Username'];
}
mysql_select_db($database_cfs, $cfs);
$query_rsCustomer = sprintf("SELECT * FROM cfsCustomers, cfsCustomersImages WHERE custEmail = %s AND cfsCustomersImages.custID = cfsCustomers.custID", GetSQLValueString($colname_rsCustomer, "text"));
$query_limit_rsCustomer = sprintf("%s LIMIT %d, %d", $query_rsCustomer, $startRow_rsCustomer, $maxRows_rsCustomer);
$rsCustomer = mysql_query($query_limit_rsCustomer, $cfs) or die(mysql_error());
$row_rsCustomer = mysql_fetch_assoc($rsCustomer);

mysql_select_db($database_cfs, $cfs);
$query_rsCount = sprintf("SELECT COUNT(*) FROM cfsCustomers, cfsCustomersImages WHERE cfsCustomers.custID = cfsCustomersImages.custID AND custEmail = %s AND imageWANT = 'Y'", GetSQLValueString($colname_rsCustomer, "text"));
$rsCount = mysql_query($query_rsCount, $cfs) or die(mysql_error());
$row_rsCount = mysql_fetch_assoc($rsCount);
$totalRows_rsCount = mysql_num_rows($rsCount);





and echoing out the results

<?php echo $row_rsCount['imageWant']; ?>

basically i was trying to get the results based on the logged in user 

Edited by jonnyfortis
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.