This topic is locked
[SOLVED]

 Sql Select Query On The Events Page

1/9/2013 6:21:57 AM
PHPRunner General questions
D
DUKE author

Hi Everyone,
On the add and edit pages of my 'weighbills' table I am running the following query:
$strSQLExists = "select rate from routes where Date Start<'" . $values["Date"] . "' and Date End>'" . $values["Date"] . "' and Route ='" . $values["Route"] . "'";

$rsExists = db_query($strSQLExists,$conn);

$correctrate=db_fetch_array($rsExists);

$values['Rate']=$correctrate;
It basically has to select the value for 'rate' from the 'routes' table where the 'date' on the add page is between 'Date Start' and 'Date End' and the 'Route' value on the add / edit page matches the value in the routes database.
When I save the information on the add/edit page I get the following error:
mysql_query() expects parameter 2 to be resource, null given
this is the query itself:
select rate from routes where Date Start<'2013-01-10 00:00:00' and Date End>'2013-01-10 00:00:00' and Route ='Kangra-R/Bay'
Can anyone help me with this, or maybe suggest an easier way that I can implement this using the "Where" or "Create new query" functions under the Lookup wizard?

C
cgphp 1/9/2013

If the query returns only one record, the correct code is:

global $conn;

$strSQLExists = "select rate from routes where `Date Start`<'" . $values["Date"] . "' and `Date End`>'" . $values["Date"] . "' and Route ='" . $values["Route"] . "'";

$rsExists = db_query($strSQLExists,$conn);

$correctrate = db_fetch_array($rsExists);

$values['Rate'] = $correctrate['rate'];
D
DUKE author 1/9/2013

Hi Christian,
Thank you very much for your help!
It works 100%