Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query returning wrong values

Status
Not open for further replies.

doccom

Technical User
Dec 20, 2003
12
US
This seems like it should be very simple but having many problems. In previous scripts I have grabed $Code and $CC, both of which return the correct values. Now I need this script to look into my db and match the Motorcycle_Type and the CCs value must be between the CC_Low and CC_High. Then I grab the Motor_Factor and display it in a combo box. This is just to make sure the right value comes out. Urgent project must be finished ASAP.



<?php //Get Motorcycle Factor with CODE and CC's
$conn_motor_factor = odbc_connect(&quot;test&quot;, &quot;&quot;, &quot;&quot;)
or die (&quot;could not connect to database.&quot;);
$query_motor_factor = &quot;SELECT Motorcycle_Type, CC_Low, CC_High, Motorcycle_Factor FROM Bodily_Injury WHERE Motorcycle_Type = '$CODE' AND ('$CC' BETWEEN CC_Low AND CC_High)&quot;;
$result_motor_factor = odbc_exec($conn_motor_factor, $query_motor_factor)
or die (&quot;could not execute query.&quot;);

echo &quot;<select name='moto_factor'>\n&quot;;

while ($row_motor_factor = odbc_fetch_array($result_motor_factor))
{
extract($row_motor_factor);
echo &quot;<option value=$Motorcycle_Factor>$Motorcycle_Factor\n&quot;;
}
echo &quot;</select>\n&quot;;
 
This might not be the whole of your problem, but I'm assuming that CC_Low and CC_High numeric, as should $CC be. You wouldn't want to quote $CC, then.

[tt]... AND ($CC BETWEEN CC_Low AND CC_High)[/tt]
 
lets say $CC = 650
In the db CC_Low has values (0,251,401,551,651,751,1001) and CC_High has values (250,400,550,650,750,1000,1330) I want to have it determine what row it fits in then grab the corresponding factor on that row. Problem is that it is grabbing the row after. Always off by one row.
Thank you for such a quick response.
 
Got it. I switched to a greater than, less than logic. after many tests, I finally got it down.

$query_motor_factor = &quot;SELECT Motorcycle_Type, CC_Low, CC_High, Motorcycle_Factor FROM Bodily_Injury WHERE Motorcycle_Type = '$CODE' AND ($CC <= CC_High AND $CC >= CC_Low)&quot;;

Thank you guys for all the help. Any other suggestions are always welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top