473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

INSERT statement problem

2
Hi,
I am writing this piece of code:
Expand|Select|Wrap|Line Numbers
  1. $sqlquery="WITH journey (TO_TOWN, STEPS, DISTANCE, WAY) 
  2. AS
  3.    (SELECT DISTINCT JNY_FROM_TOWN, 0, 0, CAST('PARIS' AS VARCHAR(MAX)) 
  4.     FROM   T_JOURNEY
  5.     WHERE  JNY_FROM_TOWN = '$do'
  6.     UNION  ALL
  7.     SELECT JNY_TO_TOWN, departure.STEPS + 1, 
  8.            departure.DISTANCE + arrival.JNY_MILES,
  9.            departure.WAY + ', ' + arrival.JNY_TO_TOWN
  10.     FROM   T_JOURNEY AS arrival
  11.            INNER JOIN journey AS departure
  12.                  ON departure.TO_TOWN = arrival.JNY_FROM_TOWN)
  13. SELECT *
  14. FROM   journey
  15. WHERE  TO_TOWN = '$to'
  16.  
  17.  
  18.  
  19. ";
  20. $results= mssql_query($sqlquery);
  21. while ($row=mssql_fetch_array($results)){
  22.  
  23. $way=$row['WAY'];
  24. echo "This is";echo "$way";
  25.  
  26. $words= split(",", $way);
  27. print_r($words);
  28.  
  29.  
  30.  
  31.  
  32. $t1=9.00;
  33.  
  34. $t2=$t1+0.1;
  35.  
  36. for ($i=0;$i<sizeof($words);$i++)
  37. {$j=$i+1;
  38. $from2=$words[$i];
  39. $to2=$words[$j];
  40.  
  41.  
  42.  
  43. $from3=strtoupper($from2);
  44. echo "$from3";
  45. $to3=strtoupper($to2);
  46. echo "$from3";
  47.  
  48.  
  49. $gool1="SELECT busno,from1,to1,time1,duration,fare FROM dbo.table4 WHERE from1= '$from3' AND to1= '$to3' AND time1>='$t1' AND time1<='$t2'";
  50. $shane=mssql_query($gool1);
  51. while ($row1=mssql_fetch_array($shane)){
  52.  
  53. $busno=$row1['busno'];
  54. echo "$busno"; 
  55. echo "   ";
  56. echo "why";
  57. $from1=$row1['from1'];
  58. echo "$from1";
  59. echo "   ";
  60. $to1=$row1['to1'];
  61. echo "$to1";
  62. echo "   ";
  63. $time1=$row1['time1'];
  64. echo "$time1";
  65. echo "   ";
  66. $duration=$row1['duration'];
  67. echo "$duration";
  68. echo "   ";
  69. $fare=$row1['fare'];
  70. echo "$fare";
  71. echo "   ";
  72. $t1=$row1['time1'] + $row1['duration'];
  73. $t2=$t1+0.1;
  74. echo "<Br>";
  75. }
  76.  
  77. }
  78.  
  79. }
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.
Sep 22 '07 #1
2 1526
pbmods
5,821 Expert 4TB
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.
Sep 22 '07 #2
gool
2
Hi,
I am writing this piece of code:
Expand|Select|Wrap|Line Numbers
  1. $sqlquery="WITH journey (TO_TOWN, STEPS, DISTANCE, WAY) 
  2. AS
  3.    (SELECT DISTINCT JNY_FROM_TOWN, 0, 0, CAST('PARIS' AS VARCHAR(MAX)) 
  4.     FROM   T_JOURNEY
  5.     WHERE  JNY_FROM_TOWN = '$do'
  6.     UNION  ALL
  7.     SELECT JNY_TO_TOWN, departure.STEPS + 1, 
  8.            departure.DISTANCE + arrival.JNY_MILES,
  9.            departure.WAY + ', ' + arrival.JNY_TO_TOWN
  10.     FROM   T_JOURNEY AS arrival
  11.            INNER JOIN journey AS departure
  12.                  ON departure.TO_TOWN = arrival.JNY_FROM_TOWN)
  13. SELECT *
  14. FROM   journey
  15. WHERE  TO_TOWN = '$to'
  16.  
  17.  
  18.  
  19. ";
  20. $results= mssql_query($sqlquery);
  21. while ($row=mssql_fetch_array($results)){
  22.  
  23. $way=$row['WAY'];
  24. echo "This is";echo "$way";
  25.  
  26. $words= split(",", $way);
  27. print_r($words);
  28.  
  29.  
  30.  
  31.  
  32. $t1=9.00;
  33.  
  34. $t2=$t1+0.1;
  35.  
  36. for ($i=0;$i<sizeof($words);$i++)
  37. {$j=$i+1;
  38. $from2=$words[$i];
  39. $to2=$words[$j];
  40.  
  41.  
  42.  
  43. $from3=strtoupper($from2);
  44. echo "$from3";
  45. $to3=strtoupper($to2);
  46. echo "$from3";
  47.  
  48.  
  49. $gool1="SELECT busno,from1,to1,time1,duration,fare FROM dbo.table4 WHERE from1= '$from3' AND to1= '$to3' AND time1>='$t1' AND time1<='$t2'";
  50. $shane=mssql_query($gool1);
  51. while ($row1=mssql_fetch_array($shane)){
  52.  
  53. $busno=$row1['busno'];
  54. echo "$busno"; 
  55. echo "   ";
  56. echo "why";
  57. $from1=$row1['from1'];
  58. echo "$from1";
  59. echo "   ";
  60. $to1=$row1['to1'];
  61. echo "$to1";
  62. echo "   ";
  63. $time1=$row1['time1'];
  64. echo "$time1";
  65. echo "   ";
  66. $duration=$row1['duration'];
  67. echo "$duration";
  68. echo "   ";
  69. $fare=$row1['fare'];
  70. echo "$fare";
  71. echo "   ";
  72. $t1=$row1['time1'] + $row1['duration'];
  73. $t2=$t1+0.1;
  74. echo "<Br>";
  75. }
  76.  
  77. }
  78.  
  79. }
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.
Ive been able to solve it myself. In fact wen i split the string of characters way, there is an space in each substring that occurs; as a result, the select statement does not work;
Sep 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
3
by: alexmaster_2004 | last post by:
hi i have made an application using C# that access sql2000. this application is just used to insert data to the database. i use something like this in my code: // string colmnA = TextBox1.Text;...
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
9
by: Jack | last post by:
Hi, I am gathering the input values to a form using Request.form method from the processing page. After all the data is captured, I am building sql statement out of it. Using a response.write...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
8
by: Red | last post by:
If auto-format is turned off in VS2008, there is apparently no way to indent a line. Under Tools->Options->Text Editor->C#->Formatting, there are three checkboxes. Unchecking those seems to cause...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Incorrect syntax near '<'. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.