Forum Moderators: open

Message Too Old, No Replies

how to connect mssql to the Predefined Variables

im working dis on 2 days but i cant find it..

         

nanat

1:43 am on May 7, 2009 (gmt 0)

10+ Year Member



guys really need Ur help.. in mysql my coding works fine but in mssql i have recieve reduntdant errors like this:

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '='. (severity 15)

mysql: WOrks Fine
============================
$result = mysql_query("select * from files order by DocTitle asc limit ".$globalOffset.", 20");

============================

mssql: T_T.. huhuhuhu...
===================================
$result = mssql_query("select top 20 * from files order by DocTitle asc, m0_folderid = ".$globalOffset);

===================================

tnx in advance..

LifeinAsia

3:24 pm on May 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You can not put "file=value" in the ORDER BY section.

What exactly is m0_folderid and what are you trying to do with it?

nanat

3:47 am on May 8, 2009 (gmt 0)

10+ Year Member



im trying to connect my sql statement from my variable name $globalOffset..

m0_folderid is my primary key..

if (isset($_GET["page"]))
{
$globalOffset = $_GET["page"];
$globalOffset = preg_replace( '/[^0-9]/', '', $globalOffset);
}
else
{
$globalOffset = 0;
}

LifeinAsia

3:31 pm on May 8, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You need a WHERE statement, which goes before the ORDER BY part. You need to try something like:
$result = mssql_query("select top 20 * from files where m0_folderid = ".$globalOffset" order by DocTitle asc);

nanat

1:49 am on May 13, 2009 (gmt 0)

10+ Year Member



$result = mssql_query("select top 20 * from files where m0_folderid = ".$globalOffset" order by DocTitle asc);

this error to me wrong syntax :D

LifeinAsia

5:51 pm on May 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It doesn't matter what YOU think is wrong. SQL determines if it is wrong or not. You may need to play around with quotes and things like that for the PHP side, but the following is correct SQL syntax:
SELECT TOP 20 *
FROM files
WHERE m0_folderid = some_value
ORDER BY DocTitle ASC

The ASC part is redundant and it will be
WHERE m0_folderid = some_value or
WHERE m0_folderid = 'some_value' depending on if some_value is numeric or a string.

nanat

12:27 am on May 14, 2009 (gmt 0)

10+ Year Member



i think the problem is the quotes or my $globalOffset has no value when i echo it the result is 0..

if (isset($_GET["page"]))
{
$globalOffset = $_GET["page"];
$globalOffset = preg_replace( '/[^0-9]/', '', $globalOffset);
}
<quotes>else
{
$globalOffset = 0;
}</quotes>

by the ways thanks alot LifeinAsia for your help for now i figure new style in a sample way "Beta"..