-1

I have that problem:

I have SQL Statement:

SELECT Amount FROM cicmpy 
  INNER JOIN (SELECT DealerCode, sum(Amount) as Amount FROM 
    (SELECT DealerCode, LOG as LogtLimit,TemporaryCreditLimit as TemporaryCreditLimit,
            CASE WHEN  TemporaryCreditLimit>0 then TemporaryCreditLimit ELSE LOG END as Amount 
            FROM LOG_DATA WHERE Status = 1 group by DealerCode) x
    on x.DealerCode=debcode where debnr is not NULL and ltrim(debcode) = '21021287'`

and I want this statement into php $query variable.

NetVipeC
  • 4,402
  • 1
  • 17
  • 19
  • $query = "SELECT Amount FROM cicmpy INNER JOIN (SELECT DealerCode, sum(Amount) as Amount FROM (SELECT DealerCode, LOG as LogtLimit,TemporaryCreditLimit as TemporaryCreditLimit , CASE WHEN TemporaryCreditLimit>0 then TemporaryCreditLimit ELSE LOG END as Amount FROM LOG_DATA WHERE Status = 1 group by DealerCode) x on x.DealerCode=debcode where debnr is not NULL and ltrim(debcode) = '21021287'" ... no? Or are you asking how to put the result of this statement in a variable? – AndreaBogazzi Apr 01 '15 at 12:24
  • no because when i call sqlsrv_query($conn,$query); and after that call sqlsrv_fetch_array there is error like this : – vakhtang pataraia Apr 01 '15 at 12:26
  • Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\log_data\test.php on line 13 – vakhtang pataraia Apr 01 '15 at 12:26
  • :facepalm: and you really think it's the **second** parameter that's bad, when error says `parameter 1`? – Forien Apr 01 '15 at 12:27
  • how can i fixed it if you have some ideas? – vakhtang pataraia Apr 01 '15 at 12:29
  • Try `var_dump( sqlsrv_errors() );` below your `sqlsrv_query`and see what it says. – TiiJ7 Apr 01 '15 at 12:31
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – IMSoP Apr 01 '15 at 12:38
  • 1
    Probably your connection is not good, booleand wiil be false. Please make a var_dump($conn) probabli is FALSE, probably you are just not connected. – AndreaBogazzi Apr 01 '15 at 13:24

1 Answers1

0

try like this,it will solve your error.

$sql = "Put your query";    //put your query in php variable
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
do stuff...
}

For More Reference

Priyank
  • 3,778
  • 3
  • 29
  • 48
  • i have this query : SELECT Amount FROM cicmpy INNER JOIN (SELECT DealerCode, sum(Amount) as Amount FROM (SELECT DealerCode, LOG as LogtLimit,TemporaryCreditLimit as TemporaryCreditLimit , CASE WHEN TemporaryCreditLimit>0 then TemporaryCreditLimit ELSE LOG END as Amount FROM LOG_DATA WHERE Status = 1 group by DealerCode) x on x.DealerCode=debcode where debnr is not NULL and ltrim(debcode) = '21021287' – vakhtang pataraia Apr 01 '15 at 12:31
  • 1
    take your query and put it where he wrote **Put your query**. If you're getting an error, it's probably that you haven't created a connection to the db. First test a really simple query to make sure you can query at all, then give it your complex query. – RightClick Apr 01 '15 at 17:16