MSSQL question
Posted: Tue Mar 30, 2004 2:35 am
I am having trouble linking to a database and was wondering if any1 in here knew what i was doing wrong.
Below is my code:
Thing is, when I run this code it brings back only the emailaddress in the list. Now this select looks fine to me, but im used to using query analyser etc.
Now, I have been given this code to work with
and it seems to work, but i dont understand why all the + and ' are there...any one shed any light on this as well as the rules for creating a query like the 2nd one.
Regards,
Steven.
Below is my code:
Code: Select all
<?php
$myServer = "blah";
$myUser = "blah";
$myPass = "blah";
$myDB = "blah";
$s = @mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
$d = @mssql_select_db($myDB, $s)
or die("Couldn't open database $myDB");
$query = "SELECT title,firstname,surname,emailaddress AS Employee FROM enquiries WHERE firstname='Steven'";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["Employee"] . "</li>";
}
mssql_free_result($rs);
mssql_close ($link);
?>Now, I have been given this code to work with
Code: Select all
<?php
$query = "SELECT title+' '+firstname+' '+surname AS Employee ";
$query .= "FROM enquiries ";
$query .= "WHERE firstname='Steven'";
?>Regards,
Steven.