Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Query in PHP

Author  Topic 

Jay87
Starting Member

41 Posts

Posted - 2010-02-08 : 06:03:04
I am using the following code:

LINE89: $slamettoday = mssql_query("SELECT COUNT(c.id) as slatoday FROM faultlog as c INNER JOIN contact ON c.contid=contact.id WHERE logged>DATEADD(DAY,-1,GETDATE()) AND response<datediff(hour,logged,(SELECT TOP 1 date FROM notes WHERE id=c.id AND id_prefix=c.id_prefix ORDER BY date ASC))". $db);
 
LINE93: $slamettoday=mssql_result($query,0,'slatoday');


In the table where i want to echo the count i call it by:

<?echo $slamettoday .  "%" ?>


I get the following errors:

PHP Warning: mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: Query failed in /var/www/helpdesk-dev/statistics.php on line 89

PHP Notice: PHP Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in /var/www/helpdesk-dev/statistics.php on line 93, referer: http://helpdesk:90/statistics.php

---------------------------------------------------------------------------------------------------------

If i run the query bit in SQL Server:

SELECT COUNT(c.id) as slatoday FROM faultlog as c INNER JOIN contact ON c.contid=contact.id WHERE logged>DATEADD(DAY,-1,GETDATE()) AND response<datediff(hour,logged,(SELECT TOP 1 date FROM notes WHERE id=c.id AND id_prefix=c.id_prefix ORDER BY date ASC))


It works fine.....

But i can't get it to work in my table...

Any ideas?

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 06:44:35
"DER BY date ASC))". $db);"

Should that be a comma?

I don't know how PHP works, but I would expect you to have to pass a ResultSet Object (i.e. the result) from LINE89 to the the mssql_result function in LINE93
Go to Top of Page

Jay87
Starting Member

41 Posts

Posted - 2010-02-08 : 06:56:19
the . joins the string i.e connecting to the database i want it to...

It's frustrating me as i am using similar queries in the table which work fine with the method i am using, like:

$query = mssql_query("SELECT Count(id) as opencalls from faultlog where logged>=dateadd(day,datediff(day,0,getdate()),0) AND logged<dateadd(day,datediff(day,0,getdate())+1,0) AND status<15", $db);

$OpenCallsToday=mssql_result($query,0,'opencalls');


this work fine and the only change i have made is the SQL query...

frustrating as hell
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 07:03:38
Well, in that example you have got a comma:

... AND status<15", $db);

you are also passing the result object ($query) from the mssql_query() call to the mssql_result() on the next line (which you weren't doing in your first example)

But as I don't know PHP I don't know if that is relevant, just making the observation. Sometimes a second pair of eyes sees things that the first pair has been staring at for hours!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 07:05:22
i.e. should the LINE 93 in the first example be:

$slamettoday=mssql_result($query$slamettoday,0,'slatoday');
Go to Top of Page

Jay87
Starting Member

41 Posts

Posted - 2010-02-08 : 07:09:03
you're right..!

spent all morning trying to work that out!!

that is frustrating
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 07:59:56
Its your round then!!
Go to Top of Page
   

- Advertisement -