Nandini Posted October 29, 2008 Share Posted October 29, 2008 Hi i want to display values from mysql table. Before display i want to check the conditions. like select * from astcdr where lastapp<>WaitExten and callednum<>$trunk; here $trunk is the trunk values from another table like select trunk from sip; Finally what i want to do is I want to display values from one table with, compare one table field with another table field. Can anyone send me the script. here is my script $sqlt=mysql_query("select * from sip"); while($rowr=mysql_fetch_array($sqlt)) { $t[]=$rowr['trunk']; } foreach($t as $v) { $where="where lastapp<>'WaitExten' and callednum<>$v"; } $sql=mysql_query("select * from astcdr $where"); while($row=mysql_fetch_array($sql)) { echo $row['accountcode']." ".$row['callednum']; echo "<br>"; } Quote Link to comment Share on other sites More sharing options...
zenag Posted October 29, 2008 Share Posted October 29, 2008 can try this..... $sqlt=mysql_query("select * from sip"); while($rowr=mysql_fetch_array($sqlt)) { $t[]=$rowr['trunk']; } $sql=mysql_query("select * from astcdr where lastapp<>'WaitExten'"); foreach($t as $v) { $sql.=" and callednum <> '".$v."'"; } while($row=mysql_fetch_array($sql)) { echo $row['accountcode']." ".$row['callednum']; echo "<br>"; } Quote Link to comment Share on other sites More sharing options...
Nandini Posted October 29, 2008 Author Share Posted October 29, 2008 this is not working. Your $sql. = something. this is out of query i think. y because $sql is already with in close braces Quote Link to comment Share on other sites More sharing options...
zenag Posted October 29, 2008 Share Posted October 29, 2008 sorry 've done a small mistake...here u go try this out..its working for me.. $sqlt=mysql_query("select * from sip"); while($rowr=mysql_fetch_array($sqlt)) { $t[]=$rowr['trunk']; } $sql="select * from astcdr where lastapp<>'WaitExten'"; foreach($t as $v) { $sql.=" and callednum <> '".$v."'"; } $sqlquery=mysql_query($sql); while($row=mysql_fetch_array($sqlquery)) { echo $row['accountcode']." ".$row['callednum']; echo "<br>"; } Quote Link to comment Share on other sites More sharing options...
Nandini Posted October 29, 2008 Author Share Posted October 29, 2008 Thanq very much zenag. Its working fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.