Jump to content

PHP / SQL


mATOK

Recommended Posts

Hi there, I would like to understand more what is returned when I perform a SQL queries.

 

I process queries all the time and use something like the below

 

$resusage = mssql_query($sqlusage);

while ($resusage1 = mssql_fetch_array($resusage)) {

echo $resusage1['username'];

}

$ttlTVA = array_count_values($resusage1);

 

Now I am trying to count with array_count_values and it gives me an error saying that the supplied argument is not an array?

 

My end goal is as follows, I am requesting records for users at a given location. I want to know how many total vaules exist between two user fields TVA and RF.

 

Right now I have:

Sum(Case r.RequestTypeId When 1 then 1 Else 0 End) As TVA,

Sum(Case r.RequestTypeId When 2 then 1 Else 0 End) As RF

 

In my SQL it spits out two numbers, TVA and RF for each user, I want a total count for the given location.

Link to comment
https://forums.phpfreaks.com/topic/72485-php-sql/
Share on other sites

It gives you this error because the value of $resusage1 after the loop is FALSE (that's what mssql_fetch_array() returns after the internal pointer in the result object reached the end).

If you want to know how many rows have been fetched, IE how many time your loop is running every time, simply use the value returned by  mssql_num_rows($resusage).

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/72485-php-sql/#findComment-365495
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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