Dynamic SQL Query?
Hello,
In the old version we could have a dynamic MySQL query string such as:
mysql_select_db($database_Domains, $Domains);
$query_rs_invoiceSUM = $sqlQuery;
$rs_invoiceSUM = mysql_query($query_rs_invoiceSUM, $Domains) or die(mysql_error());
$row_rs_invoiceSUM = mysql_fetch_assoc($rs_invoiceSUM);
$totalRows_rs_invoiceSUM = mysql_num_rows($rs_invoiceSUM);
But I can't seem to get this to work in the more modern mySQLi version:
$rs_invoices = new WA_MySQLi_RS("rs_invoices",$Domains_i,0);
$rs_invoices->setQuery("$sqlQuery");
$rs_invoices->execute();
Do we have this option?
The reason is I have a switch condition that loads various queries based on a select jump list.
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$year = $_POST["selYear"];
switch ($year) {
case "2020":
$year = '2020';
$sqlQuery = 'SELECT distinct invoices.* FROM invoices WHERE invoices.fKey = ' . $DID . ' AND year(invDate) = 2020 ORDER BY `invDate` DESC';
$sqlSumQuery = 'SELECT sum(invValue) FROM invoices WHERE invoices.fKey = ' . $DID . ' AND year(invDate) =' . $year;
$sqlClosedQuery = 'select sum(invValue) FROM invoices WHERE invoices.fKey = ' . $DID . ' AND inv_openClosed = 1 AND year(invDate) =' . $year;
break;
case "2019":
$year = '2019';
$sqlQuery = 'SELECT distinct invoices.* FROM invoices WHERE invoices.fKey = ' . $DID . ' AND year(invDate) = 2019 ORDER BY `invDate` DESC';
$sqlSumQuery = 'SELECT sum(invValue) FROM invoices WHERE invoices.fKey = ' . $DID . ' AND year(invDate) =' . $year;
$sqlClosedQuery = 'select sum(invValue) FROM invoices WHERE invoices.fKey = ' . $DID . ' AND inv_openClosed = 1 AND year(invDate) =' . $year;
break;
...etc