JoeMajesty Posted June 23, 2007 Share Posted June 23, 2007 Hi all, I'm trying to get a query working. My Apache server running on Redhat uses PHPMyAdmin 2.8.2.4 to administer MySQL 3.23.58. PHP version is 4.3.2. If I run the query below in PHPMyAdmin it returns the correct result. If I run the query on my webpage, I get "Query was empty". I'm pretty new at PHP/MySQL and programming in general, but all my other queries work. This is the first time I've tried to use the BETWEEN keyword in a query. //end pconnect.inc $thispdstart = '2007-06-04'; $thispdend = '2007-06-17'; $sql1 = 'SELECT * FROM `HrsWorked` WHERE `EmployeeNumber` = 18 AND `Date` between \'2007-06-04\' and \'2007-06-17\' ORDER BY `Date`'; '$thispdstart' and '$thispdend' ORDER BY 'Date'"; echo "$sql1<br>"; $sql1 = mysql_query($qry1, $linkID) or die (mysql_error()); Here is what I've tried: As you can see, my webpage echos the query first, then executes. The output is "query is empty". However if I copy and paste the echoed query into the SQL function in PHPMyAdmin it returns the correct results. If I use the "create PHP code" functionality from PHPMyAdmin it yields the following query and the same result on my webpage. $sql = 'SELECT * FROM `HrsWorked` WHERE `EmployeeNumber` = 18 AND `Date` between \'2007-06-04\' and \'2007-06-17\' ORDER BY `Date`'; Thanks... Link to comment https://forums.phpfreaks.com/topic/56835-solved-query-returns-empty-wphp-works-w-phpmyadmin/ Share on other sites More sharing options...
chigley Posted June 23, 2007 Share Posted June 23, 2007 <?php //end pconnect.inc $thispdstart = "2007-06-04"; $thispdend = "2007-06-17"; $sql1 = "SELECT * FROM HrsWorked WHERE EmployeeNumber = 18 AND Date BETWEEN '{$thispdstart}' AND '{$thispdend}' ORDER BY Date"; echo "{$sql1}<br />"; $sql1 = mysql_query($sql1, $linkID) or die (mysql_error()); ?> Neatened it up a little, and made the query use your variables Link to comment https://forums.phpfreaks.com/topic/56835-solved-query-returns-empty-wphp-works-w-phpmyadmin/#findComment-280830 Share on other sites More sharing options...
JoeMajesty Posted June 23, 2007 Author Share Posted June 23, 2007 Yikes, noticed a problem myself, but not a fix... There is the variable storing the query and the query results is the same. That explains "query is empty". Fixed, the code is now: $qry1 = 'SELECT * FROM `HrsWorked` WHERE `EmployeeNumber` = 18 AND `Date` between \'2007-06-04\' and \'2007-06-17\' ORDER BY `Date`'; echo "$qry1<br>"; $sql1 = mysql_query($qry1, $linkID) or die (mysql_error()); while ($row = mysql_fetch_array($sql1)) { echo $sql1['Date']."<br>"; } The only output from this page is the query. I'm not using the variables because I want fewer, well, variables until I solve this problem. I tried chigley's query and get the same result. Link to comment https://forums.phpfreaks.com/topic/56835-solved-query-returns-empty-wphp-works-w-phpmyadmin/#findComment-280839 Share on other sites More sharing options...
chigley Posted June 23, 2007 Share Posted June 23, 2007 <?php //end pconnect.inc $thispdstart = "2007-06-04"; $thispdend = "2007-06-17"; $query = "SELECT * FROM HrsWorked WHERE EmployeeNumber = 18 AND Date BETWEEN '{$thispdstart}' AND '{$thispdend}' ORDER BY Date"; echo "{$query}<br />"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<pre>".print_r($row, true)."</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/56835-solved-query-returns-empty-wphp-works-w-phpmyadmin/#findComment-280842 Share on other sites More sharing options...
JoeMajesty Posted June 23, 2007 Author Share Posted June 23, 2007 YAY. Thanks a lot Chigley. As usual, I found the errors within an hour of asking for help, I did what you suggested. 'Really appreciate it! Peace.. Link to comment https://forums.phpfreaks.com/topic/56835-solved-query-returns-empty-wphp-works-w-phpmyadmin/#findComment-280844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.