homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
what is the right syntax of dynamic mssql and php
5 hours solving the problem but i can find it
nanat

5+ Year Member



 
Msg#: 3906919 posted 7:02 am on May 5, 2009 (gmt 0)

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

5+ Year Member



 
Msg#: 3906919 posted 7:21 am on May 5, 2009 (gmt 0)

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

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



 
Msg#: 3906919 posted 9:03 am on May 5, 2009 (gmt 0)

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

5+ Year Member



 
Msg#: 3906919 posted 4:59 am on May 6, 2009 (gmt 0)


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

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



 
Msg#: 3906919 posted 11:32 pm on May 7, 2009 (gmt 0)

$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

5+ Year Member



 
Msg#: 3906919 posted 3:35 am on May 8, 2009 (gmt 0)

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

5+ Year Member



 
Msg#: 3906919 posted 4:14 am on May 8, 2009 (gmt 0)

Where is your "WHERE" clause?

camilord

5+ Year Member



 
Msg#: 3906919 posted 4:50 am on May 8, 2009 (gmt 0)

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

5+ Year Member



 
Msg#: 3906919 posted 4:55 am on May 8, 2009 (gmt 0)

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+ Year Member



 
Msg#: 3906919 posted 5:21 am on May 8, 2009 (gmt 0)

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved