Monday, March 12, 2012

INSERT statement problem

Hi,
I am writing this piece of code:
Code: ( php )
    $sqlquery="WITH journey (TO_TOWN, STEPS, DISTANCE, WAY) AS (SELECT DISTINCT JNY_FROM_TOWN, 0, 0, CAST('PARIS' AS VARCHAR(MAX)) FROM T_JOURNEY WHERE JNY_FROM_TOWN = '$do' UNION ALL SELECT JNY_TO_TOWN, departure.STEPS + 1, departure.DISTANCE + arrival.JNY_MILES, departure.WAY + ', ' + arrival.JNY_TO_TOWN FROM T_JOURNEY AS arrival INNER JOIN journey AS departure ON departure.TO_TOWN = arrival.JNY_FROM_TOWN)SELECT *FROM journeyWHERE TO_TOWN = '$to' ";$results= mssql_query($sqlquery);while ($row=mssql_fetch_array($results)){ $way=$row['WAY'];echo "This is";echo "$way"; $words= split(",", $way);print_r($words); $t1=9.00; $t2=$t1+0.1; for ($i=0;$i<sizeof($words);$i++){$j=$i+1;$from2=$words[$i];$to2=$words[$j]; $from3=strtoupper($from2);echo "$from3";$to3=strtoupper($to2);echo "$from3"; $gool1="SELECT busno,from1,to1,time1,duration,fare FROM dbo.table4 WHERE from1= '$from3' AND to1= '$to3' AND time1>='$t1' AND time1<='$t2'";$shane=mssql_query($gool1);while ($row1=mssql_fetch_array($shane)){ $busno=$row1['busno'];echo "$busno"; echo " ";echo "why";$from1=$row1['from1'];echo "$from1";echo " ";$to1=$row1['to1'];echo "$to1";echo " ";$time1=$row1['time1'];echo "$time1";echo " ";$duration=$row1['duration'];echo "$duration";echo " ";$fare=$row1['fare'];echo "$fare";echo " ";$t1=$row1['time1'] + $row1['duration'];$t2=$t1+0.1;echo "<Br>";} } }

In the above code, I am retrieving values in a variable $way. And then I am splitting the value $way into several smaller string using the function split. it works perfectly. However, when I am passing the variable $from2 and $to2 in my select statement, the statement does not recognise these variables., but wen I write these variables manually to the select statement, it then works.
How can I pass these variables so that my select staement work? I ve checked these variables($from2,$to2) whether they are of string type but they are not.
Please help me.Heya, Gool. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

I'm going to go ahead and move this thread to the MS SQL forum, where our resident Experts will be better able to help you out.|||INSERT statement problem

No comments:

Post a Comment