close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Are there times MySQL queries work differently in MySQLi ?

Thread began 3/17/2015 4:35 pm by Steve | Last modified 3/17/2015 4:56 pm by Jason Byrnes | 422 views | 4 replies |

Steve

Are there times MySQL queries work differently in MySQLi ?

For instance, this query:

SELECT * FROM inv_task WHERE inv_task.tsk_type = 4 AND inv_task.tsk_date BETWEEN '2014-1-1' AND '2017-1-1'

Fails on a web page but works in PHPmyAdmin

<?php
$Records = new WA_MySQLi_RS("Records",$Domains_i,0);
$Records->setQuery("SELECT * FROM inv_task WHERE inv_task.tsk_type = ? AND inv_task.tsk_date BETWEEN '?' AND '?'");
$Records->bindParam("i", "".$_POST['selinvoiceType'] ."", "4"); //target
$Records->bindParam("i", "".$_POST['selYear'] ."", "2015-1-1"); //targetYear
$Records->bindParam("i", "".$_POST['selYear2'] ."", "2016-1-1"); //targetYear2
$Records->execute();
?>




<body>
<!-- InstanceBeginEditable name="pageName" -->Tax Reporting<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="contentArea" -->
<h2>Business Purchases -</h2>
<p><br />
Invoice Type:
<?php echo($Records->getColumnVal("tsk_type")); ?>
<form name="form1" method="post" action="">

Type: <select name="selinvoiceType" id="selinvoiceType" onchange="this.form.submit();">
<option value=''>-- Please select --</option>
<?php
while(!$Types->atEnd()) { //dyn select
?>
<option value="<?php echo($Types->getColumnVal("tID")); ?>"<?php if (!(strcmp($Types->getColumnVal("tID"), ($Records->getColumnVal("tsk_type"))))) {echo "selected=\"selected\"";} ?>><?php echo($Types->getColumnVal("typeName")); ?></option>
<?php
$Types->moveNext();
} //dyn select
$Types->moveFirst();
?>
</select>


Year:
<select name="selYear" id="selYear" onchange="this.form.submit();">
<option value=''>-- Please select --</option>
<option value="2014-1-1" <?php if ($_POST['selYear']== '2014-1-1'){echo "selected=\"selected\"";} ?>>2014</option>
<option value="2015-1-1" <?php if ($_POST['selYear']== '2015-1-1'){echo "selected=\"selected\"";} ?>>2015</option>
<option value="2016-1-1" <?php if ($_POST['selYear']== '2016-1-1'){echo "selected=\"selected\"";} ?>>2016</option>
<option value="2017-1-1" <?php if ($_POST['selYear']== '2017-1-1'){echo "selected=\"selected\"";} ?>>2017</option>
<option value="2018-1-1" <?php if ($_POST['selYear']== '2018-1-1'){echo "selected=\"selected\"";} ?>>2018</option>
</select>

<select name="selYear2" id="selYear2" onchange="this.form.submit();">
<option value=''>-- Please select --</option>
<option value="2015-1-1" <?php if ($_POST['selYear2']== '2015-1-1'){echo "selected=\"selected\"";} ?>>2015</option>
<option value="2016-1-1" <?php if ($_POST['selYear2']== '2016-1-1'){echo "selected=\"selected\"";} ?>>2016</option>
<option value="2017-1-1" <?php if ($_POST['selYear2']== '2017-1-1'){echo "selected=\"selected\"";} ?>>2017</option>
<option value="2018-1-1" <?php if ($_POST['selYear2']== '2018-1-1'){echo "selected=\"selected\"";} ?>>2017</option>
<option value="2019-1-1" <?php if ($_POST['selYear2']== '2019-1-1'){echo "selected=\"selected\"";} ?>>2019</option>
</select>


</form>

<p>
<?php
while(!$Records->atEnd()) {
?>


$<?php echo number_format($Records->getColumnVal("tsk_value"), $decimals = 2 , $dec_point = '.' , $thousands_sep = ',' ); ?> - <?php echo($Records->getColumnVal("tsk_service")); ?> - <?php echo($Records->getColumnVal("tsk_date")); ?><br />
<?php
$Records->moveNext();
}
$Records->moveFirst(); //return RS to first record
?>
</p>

<p>&nbsp;</p>
<!-- InstanceEndEditable -->
</body>
Sign in to reply to this post

Jason ByrnesWebAssist

$Records->bindParam("i", "".$_POST['selYear'] ."", "2015-1-1"); //targetYear
$Records->bindParam("i", "".$_POST['selYear2'] ."", "2016-1-1"); //targetYear2

have the data type set to integer, that is what the i in the first argument stands for.

edit those 2 variables and set the data type to date.

Sign in to reply to this post

Jason ByrnesWebAssist

also, you shouldn't add the ' around the variable, let the data type do that.

Sign in to reply to this post

Steve

It work! Thanks.. You should consider a career in this stuff as you are really good :-)

Quotes were removed when changed to Date.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...