Hi,
I am writing this piece of code: - $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 journey
-
WHERE 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.
2 1526
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.
Hi,
I am writing this piece of code: - $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 journey
-
WHERE 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.
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;
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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...
|
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;...
|
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...
|
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...
|
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...
|
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...
|
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 '<'.
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |