Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

what is the right syntax of dynamic mssql and php

5 hours solving the problem but i can find it

     

nanat

7:02 am on May 5, 2009 (gmt 0)

5+ Year Member



acctually im a mysql user but the company want me to use mssql..

mysql:
$result2 = mssql_query("select * from users where userID = ".$globalID);

mssql:

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

whats wrong with this syntax?

$result = mssql_query("select FirstName,LastName from users where userID =" .$globalID );

nanat

7:21 am on May 5, 2009 (gmt 0)

5+ Year Member



mysql:

$result = mysql_query("select * from students order by LastName asc limit ".$globalOffset.", 20");

correct..

mssql:

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

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

what wrong with this statement?

penders

9:03 am on May 5, 2009 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Is your userID field a string and needs to be quoted?

I'm unfamilar with this syntax:

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

Do you need the = after asc?

nanat

4:59 am on May 6, 2009 (gmt 0)

5+ Year Member




even if this i change it with ;

$result = mssqL_query("select * top 20 from files where DocTitle = ". $globalOffset);

it doesnt work at all do think ds statement is right
= ". $globalOffset?

penders

11:32 pm on May 7, 2009 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



$result = mssqL_query("select * top 20 from files where DocTitle = ". $globalOffset);

This does not look quite right to me. Presumably DocTitle is a string/varchar field and its value needs to be quoted in the SQL (MySQL or MSSQL)....?

ie.

$result = mssql_query("select top 20 * from files where DocTitle = '". $globalOffset."'");

nanat

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

5+ Year Member



even if i change it to dis.. the same error..

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

tnx penders for helping me i really Appreciate it..
m_folderid = my primary key

BarryStCyr

4:14 am on May 8, 2009 (gmt 0)

10+ Year Member



Where is your "WHERE" clause?

camilord

4:50 am on May 8, 2009 (gmt 0)

5+ Year Member



i think the right statement is...

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

though i'm not into mssql.. hehehehe.. mssqll sucks! no offense to mssql fan.. :)

camilord

4:55 am on May 8, 2009 (gmt 0)

5+ Year Member



i think you also name you variable to a good one since your pointing the primary key... like;

$globalID = $_GET["id"];

$result = mssql_query("SELECT top 20 * FROM files WHERE m_folderid = '".$globalID."' ORDER BY DocTitle ASC");

nanat

5:21 am on May 8, 2009 (gmt 0)

5+ Year Member



dis statement = no result post because of where..

$result = mssql_query("SELECT top 20 * FROM files WHERE m_folderid = '".$globalOffset."' ORDER BY DocTitle ASC");

i tried dis dis script but there is an error

$result = mssql_query("SELECT top 20 * FROM files m_folderid = '".$globalOffset."' ORDER BY DocTitle ASC");
======================================================
dis is my script

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

[edited by: eelixduppy at 6:27 am (utc) on May 8, 2009]
[edit reason] no URLs, please [/edit]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month