PHP Will Not Echo Results On Screen

111 views Asked by At

I am attempting to run the above statement from an onclick() event of a button. I can echo my variables $qtr, $saleqtr, $startdate, $enddate on screen but for some reason the sql statement that I am attempting to throw together never echo (nor does it execute, which is why I want to see the string).

Do I have a simple syntax mistake or is the issue elsewhere?

<?php
    if (isset($_POST['submit'])) {      
        $saleqtr = $_POST['qtr'];
                if ($saleqtr == "first") { $startdate = '20150101'; $enddate = '20150331';  }
        if (isset($startdate) && isset($enddate)) {
            $customername = $_POST['customer'];
            $option = array();
            $option['driver'] = 'mssql';
            $option['host'] = 'X';
            $option['user'] = 'user';
            $option['password'] = 'pass';
            $option['database'] = 'db';
            $option['prefix'] = '';
            $db = JDatabase::getInstance($option);
            $sql = $db->getquery(true);
            $sql = "SELECT Top 1 name from name where hiredate >= '$startdate' And hiredate <= '$enddate'";
        }
        echo $sql;
    }
?>

EDIT
Below is my click event

<body>
    <form method="POST">
        <input type="submit" name="submit" value="Click Me">
    </form>
</body>
1

There are 1 answers

1
Sean Jermey On BEST ANSWER

When you call $db->getquery(true); you are creating a joomla query object, said object has a __toString() function so the below should work for you.

echo $sql->__toString();

EDIT

Try this.

$sql = $db->getquery(true);
$sql->select("Top 1 name from name where hiredate >= '$startdate' And hiredate <= '$enddate'");

echo $sql->__toString();