Forum Moderators: coopster
//THIS CALCULATES THE TOTAL RATING GIVEN WHEN ALL CATEGORIES ARE NOT NR RESPONSE.
$totalraterows=mysql_query("SELECT * FROM table WHERE ((response !='NR' AND quotable !='NR') AND (vendorusername='$webinfo2'))");
$total9=0;
while ($totalrows = mysql_fetch_array($totalraterows)) {
$total9=mysql_affected_rows();}
you could use count
SELECT count(columnname) as mybigtotal FROM table WHERE ((response !='NR' AND quotable !='NR') AND (vendorusername='$webinfo2')
if you need to get a row afterwards that has different values then I would issue a different query
Try mysql_num_rows [us.php.net]
//THIS CALCULATES THE TOTAL RATING GIVEN WHEN ALL CATEGORIES ARE NOT NR RESPONSE.
$totalraterows=mysql_query("SELECT * FROM table WHERE ((response !='NR' AND quotable !='NR') AND (vendorusername='$webinfo2'))");
$total9=0;
$total9=mysql_num_rows($totalraterows); // you don't need the while loop
If memory serves mysql_affected_rows won't return anything for a SELECT query.
True. The relative mysqli function [php.net] works a little differently though.
>>where quote and response are both not nr. (first message)
>>only true when BOTH columns are NR. (last message)
>>I need it to pull a row when response=NR and quotable=1 (last message)
... but it is becoming clear now. You are actually checking the value of just this part of the WHERE condition expression, not the entire SQL statement.
If you want a TRUE response returned for this portion of the conditional expression when either the response OR quotable value is not equal to 'NR' then you have your condition correct now. Except for one thing, change those pipes to the SQL boolean "OR" operator because pipe symbols in standard sql statements typically translate to concatenation, especially for database servers running in ANSI mode, which is closer to standard SQL.
MySQL Server understands the ¦¦ and && operators to mean logical OR and AND, as in the C programming language. In MySQL Server, ¦¦ and OR are synonyms, as are && and AND. Because of this nice syntax, MySQL Server doesn't support the standard SQL ¦¦ operator for string concatenation; use CONCAT() instead.
MySQL Extensions to Standard SQL [dev.mysql.com]
PIPES_AS_CONCAT [dev.mysql.com]
Running MySQL in ANSI Mode [dev.mysql.com]
So confused. I hope this helps the communication problem.
I really want to pull data from the database when ROW 1: field A is not NR at the same time field B is not NR. The AND in between did not get the desired result I thought it would.
Then you are wording your plain text phrase here incorrectly because your original code says exactly that:
(response !='NR' AND quotable !='NR')That code says to return TRUE when ROW 1:
field A [response] is not [!=] NR AND ["at the same time"] field B [quotable] is not [!=] NR.
(response != 'NR' OR quotable != 'NR')That code says to return TRUE when ROW 1:
field A [response] is not [!=] NR OR ["either this is TRUE OR the next is TRUE"] field B [quotable] is not [!=] NR.