Search the Community
Showing results for tags 'mssql'.
-
Hello All, I'm trying to use PHP to post to MSSQL server, I can get a connection however when I attempt my MSSQL Statement the query just won't work. This is most troubling, anyone have any suggestions Here's my code $conn = mssql_connect( 'myServer', "username", 'password', 'database' ) or die('Error Connecting'); $sql = "INSERT INTO Employees (Area, isTicketRep) VALUES ('789456', '1')"; mssql_query($conn, $sql) or die('Error Querying MSSQL Database'); mssql_close($conn); I have tried an if statement to ensure a connection, I have a connection....however the query just wont execute. There are numerous column on my database table but I'm only submitted selected field. In addition the actual table is called "Employees" but on the server reads "dbo.Employees". My Database is called "cs_all" Just won't seem to query, thanks in advance for any suggestions
-
I have 5 dropdowns on a tab of a website. I have a database table in MS SQL Server. The table has all the data of 5 dropdowns with one of the fieldNames called Region_Name, say the Region_Names are A, B, C, D, and E. I have written codes to display a table and enabled row editing for one of the RegionNames. Now, I am wondering if I could modify the same codes to display associated table with row editing enabled using different queries when a dropdown is clicked. That could reduce the code repetition and improve the performance. But I do not know how to achieve this. Could anyone please give me some hints? I am using PHP PDO to connect to the database.
-
Hi, I have a Procedures ready to auto send email to employee when the reminder date equal today. Let me show you what is inside my employee database. As you can see, there is two records for employee 1001. This is because this employee short notice for 2 months. [sdate] There is also a shortNotice which is in December is 4 day, in January is 18 days. So, the consist days is 18+4=22 Days This is my procedure code, it's working, this procedure will trigger out email if meet the criteria. ***REMEMBER TO CHANGE THE SERVER NAME & PORT NUMBER*** USE [RSA] GO /****** Object: StoredProcedure [dbo].[sp_send_cdosysmail] Script Date: 12/10/2015 3:55:00 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_send_cdosysmail] @From varchar(100)="notification@mail.com", @Subject varchar(100)="A Reminder for you", @body varchar(4000)=" ", @attachments varchar(4000)=NULL AS DECLARE @out_desc VARCHAR(1000), @out_mesg VARCHAR(10) DECLARE @empid nvarchar(255), @Name nvarchar(255), @Email nvarchar(255), @reminderDate datetime, @lastDay datetime, @shortNotice int, @consistsDays int, @sdate datetime Declare C1 CURSOR READ_ONLY FOR SELECT DISTINCT [empid],[Name],[Email],[reminderDate],[lastDay],[shortNotice],[consistsDays],[sdate] FROM [resigntblView] Declare @iMsg int Declare @hr int Declare @source varchar(255) Declare @description varchar(500) Declare @output varchar(1000) Declare @files table(fileid int identity(1,1),[file] varchar(255)) OPEN C1 FETCH NEXT FROM C1 INTO @empid,@Name, @Email, @reminderDate, @lastDay,@shortNotice,@consistsDays,@sdate WHILE @@FETCH_STATUS = 0 BEGIN IF DATEPART(DAY,@reminderDate) = DATEPART(DAY,GETDATE()) AND DATEPART(MONTH,@reminderDate) = DATEPART(MONTH,GETDATE()) AND DATEPART(YEAR,@reminderDate) = DATEPART(YEAR,GETDATE()) BEGIN SET @body = '<b>Hi ' + @Name + '</b><br />This is a reminder' + '<br /><br />Thank You' --************* Create the CDO.Message Object ************************ EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT --***************Configuring the Message Object ****************** -- This is to configure a remote SMTP server. -- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.asp EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields ("http://schemas.microsoft.com/cdo/configuration/sendusing"). Value','2' -- This is to configure the Server Name or IP address. -- Replace MailServerName by the name or IP of your SMTP Server. EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver"). Value', '#######' --PUT YOUR SERVER HERE -- Save the configurations to the message object. EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null -- Set the e-mail parameters. EXEC @hr = sp_OASetProperty @iMsg, 'To', @Email EXEC @hr = sp_OASetProperty @iMsg, 'From', @From EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject -- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'. EXEC @hr = sp_OASetProperty @iMsg, 'HTMLBody', @body EXEC @hr = sp_OAMethod @iMsg, 'Send' -- Do some error handling after each step if you need to. -- Clean up the objects created. EXEC @hr = sp_OADestroy @iMsg END FETCH NEXT FROM C1 INTO @empid,@Name, @Email, @reminderDate,@lastDay,@shortNotice,@consistsDays,@sdate END CLOSE C1 DEALLOCATE C1 Once the Procedures is execute, this is the OUTPUT that i received in my inbox: Hi Foo, Kelvin This is a reminder Thank You This Email will Trigger two times since there is a two column of data. My question is, how to merge some of the data in one, and send the email only once. Expected Output: Hi Foo, Kelvin, You are required to compensate USD 100 to the Company in view of your 22 days of short notice. The 1 month of your notice period consist of 22 working days, (01-12-2015 - 31-12-2015), 4 Days The 2 month of your notice period consist of 22 working days, (01-01-2016 - 31-01-2016), 18 Days Thank You. Thanks for your big help.
-
Hello, I have a question regarding SQL. Please refer my attachment below: Query 1: SELECT dbo.[evaluation[Submit]]].FormID, dbo.empDB.Name, dbo.FormTbl.FormName, dbo.[evaluation[Submit]]].groupName, dbo.[evaluation[Submit]]].subGroup, dbo.subgrouptbl.subgroupName FROM dbo.[evaluation[Submit]]] INNER JOIN dbo.empDB ON dbo.[evaluation[Submit]]].EmpID = dbo.empDB.EmployeeID INNER JOIN dbo.FormTbl ON dbo.[evaluation[Submit]]].FormID = dbo.FormTbl.FormID INNER JOIN dbo.subgrouptbl ON dbo.[evaluation[Submit]]].subGroup = dbo.subgrouptbl.subgroupID WHERE (dbo.[evaluation[Submit]]].EmpID = '00001') This view of table give me correct of the output. Which give me 36 of results. Please refer attachment below: But, when i try to put additional table which i need to indicated whether the form is completed or draft, it's because i do not want to show "draft" form in the table. Have a look on the table below: After i added this table into my view, the output is repeated 2 times and give me 72 of results. Query 2: SELECT dbo.[evaluation[Submit]]].FormID, dbo.empDB.Name, dbo.FormTbl.FormName, dbo.[evaluation[Submit]]].groupName, dbo.[evaluation[Submit]]].subGroup, dbo.subgrouptbl.subgroupName, dbo.EmployeeDetails.submissionStatus FROM dbo.[evaluation[Submit]]] INNER JOIN dbo.empDB ON dbo.[evaluation[Submit]]].EmpID = dbo.empDB.EmployeeID INNER JOIN dbo.FormTbl ON dbo.[evaluation[Submit]]].FormID = dbo.FormTbl.FormID INNER JOIN dbo.subgrouptbl ON dbo.[evaluation[Submit]]].subGroup = dbo.subgrouptbl.subgroupID INNER JOIN dbo.EmployeeDetails ON dbo.empDB.EmployeeID = dbo.EmployeeDetails.EmpID WHERE (dbo.[evaluation[Submit]]].EmpID = '00001')
-
I have a stored procedure with 2 parameters. I'm able to execute stored procedures with one parameter using the same script below. But I couldn't make it work with two parameters. $stmt = "{CALL VM_GETPRs_CAMPS (?,?)}";**//SP has 160 rows of data.** $fdate=date("Y-m-d"); $tdate=date("Y-m-d"); $params = array( array($fdate,SQLSRV_PARAM_IN), array($tdate,SQLSRV_PARAM_IN) ); $result = sqlsrv_query( $conn, $stmt,$params,array('Scrollable' => 'buffered')); //not getting any error if( $result === false) { die( print_r( sqlsrv_errors(), true) ); } else{ **//**I tried sqlsrv_num_rows and sqlsrv_has_rows sqlsrv_fetch_array all are giving zero rows.** $row_count = sqlsrv_num_rows( $result ); if ($row_count === false) echo "No rows"; else if ($row_count >=0) echo "\n$row_count\n"; //outputs 0 ---------------------------------- if(sqlsrv_has_rows($result)) echo "has rows"; else echo "No rows"; //outputs No rows ---------------------------------- $data = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); var_dump($data); //outputs bool(false) I'm looking for a solution since four days. Please help me.
-
This is posting to any row in mssql that has a matching 'start_date'. I would like it to post rows where start_date = '$start_date' and it also matches the 'meter_id' . It should perform this check of both parameters before posting to mssql. <?php $session_id = $_SESSION['id']; $comm_id = $_GET['meter_id']; $start_date = $_GET['start_date']; $payment_date = $_POST['payment_date']; $amount_paid = $_POST['amount_paid']; $check_number = $_POST['check_number']; $sql = "UPDATE [radiogates].[dbo].[ops_invoice_history] SET payment_date = '$payment_date', amount_paid = '$amount_paid', check_number = '$check_number' where start_date = '$start_date'"; $query = sqlsrv_query($conn, $sql); Thank you for any help.
-
Good morning, I am trying to return specific values depending on the value of the WJCStatusID, for example if WJCStatusID = < 4 but > 2 return "In production" SQL QUERY: SELECT tblWJCItem.AddedDescription, tblWJC.WJCPrefix + Convert(Varchar(10),tblWJC.WJCNo) AS OurRef, tblWJCItem.MaterialName, tblStockFamily.StockFamily, tblWJCItem.WeightToSend, tblWJC.DateCreated, tblWJC.WJCStatusID FROM tblWJC INNER JOIN tblWJCItem ON tblWJC.WJCID = tblWJCItem.WJCID INNER JOIN tblStockFamily ON tblWJCItem.ProductFamilyID = tblStockFamily.StockFamilyID IF (tblWJC.WJCStatusID) < 2 THEN 'Pre Production' ELSE IF (tblWJC.WJCStatusID) < 4 THEN 'In Production' ELSE IF (tblWJC.WJCStatusID) > 4 THEN 'Ready To Ship' ELSE 'Awaiting Lab Results'; I am quite new to the world of mssql so I maybe doing something wrong which is quite simply to fix. Can any body help?
-
Hello, I am trying to run a report as per the below mssql query: $query = "SELECT tblWJCItem.AddedDescription, tblWJC.WJCPrefix, tblWJC.WJCNo, tblWJCItem.MaterialName, tblStockFamily.StockFamily, tblWJCItem.WeightToSend, tblWJC.DateCreated, tblWJC.WJCStatusID FROM tblWJC INNER JOIN tblCustomer ON tblWJC.CustomerID = tblCustomer.CustomerID INNER JOIN tblWJCStockStatus ON tblWJC.WJCStockStatusID = tblWJCStockStatus.WJCStockStatusID INNER JOIN tblStockStatus ON tblWJC.WJCID = tblStockStatus.WJCID LEFT OUTER JOIN tblWJCProductLine ON tblWJC.WJCID = tblWJCProductLine.WJCID LEFT OUTER JOIN tblWJCStockItem ON tblWJCProductLine.WJCProductLineID = tblWJCStockItem.tblWJCStockItem INNER JOIN tblStockFamily ON tblWJCItem.ProductFamilyID = tblStockFamily.StockFamilyID WHERE tblCustomer.CustomerName = 'NAME' AND tblWJCStockStatus.WJCStockStatus <> 'Stock Usage Confirmed' ORDER BY tblWJC.WJCID"; and then fetch the results by the following php code: $result = sqlsrv_query($conn, $query); while($row = sqlsrv_fetch_object($result)){ echo $row->AddedDescription .",".$row->WJCPrefix .",".$row->WJCNo.",".$row->MaterialName.",".$row->StockFamily.",".$row->WeightToSend.",".$row->DateCreated->format('d-m-Y').",".$row->WJCStatusID ."<br />"; } The connection to the database does get established but no results come through, i've got error reporting on in my php and the following message gets given: Warning: sqlsrv_fetch_object() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\kris\abs\test\rollsroyce.php on line 31 Line 31 is the while($row = sqlsrv_fetch_object($result)) Can anyone help with sorting this out its really starting to annoy me now. .
-
Good morning, I am doing a small project including google charts API but I am having trouble getting my results into the json format that is required. Google's documentation states the json format should be: { "cols": [ {"id":"","label":"Topping","pattern":"","type":"string"}, {"id":"","label":"Slices","pattern":"","type":"number"} ], "rows": [ {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]}, {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]}, {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]}, {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]}, {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]} ] } the query works perfectly fine thats not the problem but getting it into the above format is proving hard than I expected. The below is what I am trying to do to populate the json data in the correct format. function graphdata() { $array['cols'][] = array('type' => 'string'); $array['cols'][] = array('type' => 'string'); $array['cols'][] = array('type' => 'string'); $result = sqlsrv_query($conn, $query); while($row = sqlsrv_fetch_object($result)){ $array['rows'][] = array('c' => array( array('v'=>'$row->DateCreated->format('d-m-Y')'), array('v'=>$row->UnitPrice)) ); } return $array; } print json_encode(graphdata()); I am using MSSQL and not the normal mysql hence the above code, i am a starter when it comes to php so I may be doing something basic totally wrong but I cannot seem to get it to work. Thanks
-
Good morning, I am trying to convert a mssql query into json format so that I can then later pass this through google's visualisation api. The query and encoding seems to be working but the encode returns NULL. I have checked the normal gotcha's of making sure its utf8 encoded and that I have used a version of PHP that has the encode (using php 5.3.19). Can any one help me with getting the encode to work. PHP CODE: <?php //connection and database details (known to be working) if( $conn ) { echo "Connection established.<br><br>"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } $query = "SELECT * FROM tblProducts"; $result = sqlsrv_query( $conn, $query); while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_NUMERIC) ); $arr = array($result); $encodedarray = array_map(utf8_encode, $arr); echo json_encode($encodedarray); sqlsrv_close( $conn); ?> When I run this code on the server it comes back with: Connection established. [null] Has anyone got any ideas of getting this to work? Thanks Kris
-
I need help changing the back ground color of a field. the below code sets the background color of my field to red(I have highlighted the code in red that does this.) What I want to do is change that color when the sql field WIP_master.uompScheduleColor changes.So i think I would want an if statement to do this but I am not sure where to start since the field I will be looking at is in the sql statment. WIP_master.uompScheduleColor data looks like this: CRIMSON NEON BLUE PINK SILVER GREEN YELLOW my code so far: <html> <head> <title>PHP SQL Test</title> </head> <body> <p> Status Screen </p> <?php $bgcolor="#FF0000"; $connect =odbc_connect("REMOVED"); if(!$connect) { exit("Connection Failed: " . $connect); } $sql=" SELECT distinct WIP_master.uompScheduleNumber,WIP_master.uompScheduleColor ,WIP_locations.location_name ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '2' ) as Printed ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '3' ) as Audited ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '9' ) as Shortage ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '10' ) as Shortage_Prt ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '11' ) as Red ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '12' ) as Neon ,( SELECT COUNT(*) FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master1 LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations WIP_locations1 ON WIP_master.location = WIP_locations1.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status1 ON WIP_master.STATUS = WIP_status1.STATUS WHERE WIP_master.uompScheduleNumber =WIP_master1.uompScheduleNumber and WIP_master1.status = '20' ) as QC_Hold FROM OrbeData_KithKitchens.dbo.WIP_master WIP_master LEFT JOIN OrbeData_KithKitchens.dbo.WIP_locations ON WIP_master.location = WIP_locations.location LEFT JOIN OrbeData_KithKitchens.dbo.WIP_status WIP_status ON WIP_master.STATUS = WIP_status.STATUS order by WIP_master.uompScheduleNumber " ; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } echo "<table><tr>"; echo "<th>ScheduleNumber</th>"; echo "<th>Location</th>"; echo "<th>Printed</th>"; echo "<th>Audited</th>"; echo "<th>Shortage</th>"; echo "<th>Shortage_Prt</th>"; echo "<th>Red</th>"; echo "<th>Neon</th>"; echo "<th>QC_Hold</th>"; while (odbc_fetch_row($result)) { $uompScheduleNumber=odbc_result($result,"uompScheduleNumber"); $location_name=odbc_result($result,"location_name"); $Printed=odbc_result($result,"Printed"); $Audited=odbc_result($result,"Audited"); $Shortage=odbc_result($result,"Shortage"); $Shortage_Prt=odbc_result($result,"Shortage_Prt"); $Red=odbc_result($result,"Red"); $Neon=odbc_result($result,"Neon"); $QC_Hold=odbc_result($result,"QC_Hold"); echo "<tr><td bgcolor=$bgcolor >$uompScheduleNumber</td>"; echo "<td>$location_name</td>"; echo "<td>$Printed</td>"; echo "<td> $Audited</td>"; echo "<td> $Shortage</td>"; echo "<td> $Shortage_Prt</td>"; echo "<td> $Red</td>"; echo "<td> $Neon</td>"; echo "<td> $QC_Hold</td>"; } odbc_close($connect); ?> </body> </html>
-
Troubles abound. What I am trying to achieve is to populate a form using data from a MSSQL database. First, the user will select a company from a dropdown list **WORKING** Then, the company name will appear on the form **WORKING** Now, as the code is set below, the Customer Number, Address, etc WILL populate, but only from the last record in the database. While the company name will change upon selection of the dropdown menu, everthing else remains the same. I am using $_POST to populate the company name from the dropdown. Here is my code: echo "<table border ='0' width='90%'><tr><td align='center'><strong><font size='4'><font color='#008301'>Load Customer</font></strong></td></tr></table>"; echo "<table border ='1' width='90%'><tr><td>"; echo "<form method=\"post\" action='salesquote.php'>"; echo "<select name=\"pcsname\">"; echo "<option>Select Company</option>"; $sql="select csname, cscode from customer where sacode = $sacode order by csname"; $rs=odbc_exec($conn,$sql); if (!$rs) echo"Error in SQL"; while(odbc_fetch_row($rs)) { $csname=odbc_result($rs,"csname"); echo "<option value=\"$csname\">$csname</option>"; } echo "</select>"; echo "<input type=\"submit\">"; echo "</form>"; echo "</td></tr>"; echo "</table>"; echo "</form>"; echo "</tr></table>"; echo "<br />"; odbc_close($conn); echo "<table border ='0' width='100%'><tr><td align='center'><strong><font size='4'><font color='#008301'>Quote Information</font></strong></td></tr></table>"; echo "<table border ='1' width='100%'>"; echo "<tr><td>Quote Date</td>"; echo "<td>"; echo date("F d, Y"); echo "</td></tr>"; echo "<tr><td>Inquiry Date</td>"; echo"<td><input type='text' size='20'></td></tr>"; echo "<tr><td>Sales Person $pcscode</td>"; echo "<td>"; ?><?php include 'addons/loginArray.php';?><?php echo "</td></tr>"; echo "</table>"; echo "<br />"; echo "<table border ='0' width='100%'><tr><td align='center'><strong><font size='4'><font color='#008301'>Customer Information</font></strong></td></tr></table>"; echo "<table border ='1' width='100%'>"; include 'addons/connection.php'; $sql="select cscode, csphone, csaddr1, csaddr2, cscity, csst, cszip from customer where sacode = $sacode order by csname"; $rs=odbc_exec($conn,$sql); if (!$rs) echo"Error in SQL"; while(odbc_fetch_row($rs)) { $cscode=odbc_result($rs,"cscode"); $csphone=odbc_result($rs,"csphone"); $csaddr1=odbc_result($rs,"csaddr1"); $csaddr2=odbc_result($rs,"csaddr2"); $cscity=odbc_result($rs,"cscity"); $csst=odbc_result($rs,"csst"); $cszip=odbc_result($rs,"cszip"); } echo "<tr><td width=\"40%\">Customer Number</td>"; echo"<td>$cscode</td></tr>"; echo "<tr><td>Company Name</td>"; echo "<td>$pcsname</td></tr>"; echo "<tr><td>Customer Phone</td>"; echo "<td>$csphone</td></tr>"; echo "<tr><td>Address 1</td>"; echo "<td>$csaddr1</td></tr>"; echo "<tr><td>Address 2</td>"; echo "<td>$csaddr2</td></tr>"; echo "<tr><td>Address 3</td>"; echo "<td>$cscity $csst $cszip</td></tr>"; odbc_close($conn); echo "</table>"; If, however, I do somethiong like this: $sql="select cscode, csphone, csaddr1, csaddr2, cscity, csst, cszip from customer where sacode = $sacode and csname = $pcsname"; I would expect this to give me the required information by referencing the company name already set above. Instead, I get an SQL ERROR Again, if I remove the line: csname = $pcsname I get the last record in the databse associated with $sacode. any thoughts? Thank you in advance
-
I am trying to figure this out. When I run the below code, I DO get spaces inside my <select><option></option></select> code, but I can not see anything but blank spaces. echo "<table border ='1' width='90%'><tr><td>"; echo "<select name=\"test\">"; $sql="select csname from customer where sacode = $sacode"; $rs=odbc_exec($conn,$sql); if (!$rs) echo"Error in SQL"; while($row=odbc_fetch_row($rs)) { echo "<option value=.$row[csname].</option>"; } echo "</select>"; echo "</td></tr>"; odbc_close($conn); echo "</table>"; When I run the same code to output into a table, everything is fine. Any ideas?
-
I have the query below which works great. Alls I want to do is all the projects from the query grouped by the description. $query_rs_installs = "SELECT Calls.Call_Ref, Calls.Link_to_Contract_Header, Calls.Order_No, Calls.Date_Received, Calls.Scheduled_Date_Time, Clients.Co_Name, Clients.Post_Code, LU_Call_Types.Call_Type_Description, LU_Call_Types.Type_Band, LU_Call_Status.Call_Status_Description, LU_Company_Types.Company_Type_DescriptionFROM { oj (((Siclops_Dispense.dbo.Calls Calls INNER JOIN Siclops_Dispense.dbo.LU_Call_Types LU_Call_Types ON Calls.Call_Type = LU_Call_Types.Call_Type_Code) INNER JOIN Siclops_Dispense.dbo.LU_Call_Status LU_Call_Status ON Calls.Last_Event_Status = LU_Call_Status.Call_Status_Code) INNER JOIN Siclops_Dispense.dbo.Clients Clients ON Calls.Link_to_Client = Clients.Client_Ref) LEFT OUTER JOIN Siclops_Dispense.dbo.LU_Company_Types LU_Company_Types ON Clients.Company_Type = LU_Company_Types.Company_Type_Code}WHERE Calls.Link_to_Contract_Header = '".$row_rs_member['companyident']."' AND (LU_Call_Types.Type_Band = 'Project' OR LU_Call_Types.Type_Band = 'Project Complete' OR LU_Call_Types.Type_Band = 'Project Invoiced') AND (LU_Call_Status.Call_Status_Description = 'Reported Done' OR LU_Call_Status.Call_Status_Description = 'PTF Rep Done' OR LU_Call_Status.Call_Status_Description = 'Proforma Sent' OR LU_Call_Status.Call_Status_Description = 'Paperwork Recvd' OR LU_Call_Status.Call_Status_Description = 'In Query' OR LU_Call_Status.Call_Status_Description = 'Cryo PW Sent' OR LU_Call_Status.Call_Status_Description = 'Complete' OR LU_Call_Status.Call_Status_Description = 'Awaiting P/work' OR LU_Call_Status.Call_Status_Description = 'Awaiting Invoic' OR LU_Call_Status.Call_Status_Description = 'Await TB Return' OR LU_Call_Status.Call_Status_Description = 'ApplicationSent')GROUP BY LU_Call_Status.Call_Status_Description"; Now before the group by the query works fine. As soon as i write it in the query fails completely. I have also tried selecting distinct and unique on the same field but each time I write them in it fails. I believe this maybe because this is an MS SQL query and as such I may have the syntax wrong. Any ideas? Thanks guys
-
Hi, I am new in PHP. I have tried to connect MSSQL 2005 through php. I am using xampp 1.8.0 But once run, error msg is "Fatal error: Call to undefined function mssql_query()". I have copied "php_mssql.dll" in PHP folder and enable in PHP.ini as "extension=php_mssql.dll " and also tried copied in PHP/ext folder also (all above got from forum PHP Freaks Previous topics) But nothing happened. Same error appear. Can anybody help? Pls Help me. Below is code. I am running xampp in my local mechine with Win 7 pro It is config.php <?php $myServer = "sils-pc"; $myUser = "sa"; $myPass = "544Hjy%2*2"; $myDB = "tempDB"; $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; $conn->open($connStr); ?> <?php include 'config.php'; $query = "SELECT * FROM vw_Film_Certs_Display order by id"; //$query = mssql_query('SELECT * FROM .[dbo].[vw_Film_Certs_Display]');$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["id"] . $row["name"] . $row["year"] . "</li>";}mssql_close($dbhandle);?> Please help me
-
Hi everyone, when I run my view, this is the result that I get: This is my view: <p>Hello world</p> <?php $this->headLink()->appendStylesheet($this->serverUrl($this->baseUrl('/css/continuity-form-style-v3.css')), $media = "all"); $pv = $this->patientVisit; /* @var $pv Application_Model_Entity_PatientVisit */ $reports= $pv->getReports();/* @var Application_Model_Entity_CPM */ ?> <div> <?php // find the type of report that the user would like to retrieve. $reportType = $request->getParam('report_type'); if ('dischargedWithoutDinstr' == $reportType) { } elseif ('dischargedFaxStatus' == $reportType) { } elseif ('dischargedFaxStatusWeek' == $reportType) { } // this executes faxStatusRecent when there are no other options. else { } ?> </div> Now, what am I doing wrong? Am I missing something? Should I show more code of some sort?
-
Hello all, I have a Windows Server 2008 R2 Standard 64-bit server running WAMP 2.2 along with PHP 5.3.13 and a SQL Server Enterprise 64-bit. SQLSRV is registered as a PHP stream using Microsoft Drivers 3.0 for PHP and SQL Server. The connection is made without issue and the query is working as it should, the only problem is that I haven't figured out the correct way to display what is returned by the query. Maybe you all might be able to help me out! Here's a look at a couple things I've been trying. if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } $query = "SELECT top (10) docid, sequence, server, share, path, filename "; $query .= "FROM files "; $query .= "WHERE filename like '%2008010639029%'"; $result = sqlsrv_query($conn, $query) or die (sqlsrv_errors()); if(sqlsrv_has_rows($result)){ echo "1 or more rows have been returned<br />";} else {echo "No results were found.<br />";} while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { print_r ($row); } When that script is run the results of the query are correct it is just displayed like so: Here is the other method that I'm using that gets close. if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } $query = "SELECT top (10) docid, sequence, server, share, path, filename "; $query .= "FROM files "; $query .= "WHERE filename like '%2008010639029%'"; $result = sqlsrv_query($conn, $query) or die (sqlsrv_errors()); if(sqlsrv_has_rows($result)){ echo "1 or more rows have been returned<br />";} else {echo "No results were found.<br />";} while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { $docid = sqlsrv_get_field($result, 0); $sequence = sqlsrv_get_field($result, 1); $server = sqlsrv_get_field($result, 2); $share = sqlsrv_get_field($result, 3); $path = sqlsrv_get_field($result, 4); $filename = sqlsrv_get_field($result, 5); echo "$docid" . "$sequence, " . "$server, " . "$share, " . "$path, " . "$filename, " . '<br />'; } The result is: Do you all have any suggestions? Thanks a ton for looking at this.
-
I'm running: Windows Server 2003 IIS 6.0 Microsoft SQL 2005 PHP 5.3.28 Everything that i have read says, "5.3 got rid of mssql and now uses sqlsrv" so i added extension=php_sqlsrv_53_nts_vc9.dll to my php.ini (and yes it is in the ext folder) and when i run the script $serverName = "localhost\phonebook"; //serverName\instanceName // Since UID and PWD are not specified in the $connectionInfo array, // The connection will be attempted using Windows Authentication. $connectionInfo = array( "Database"=>"XXXXX", "UID"=>"XXXXX", "PWD"=>'XXXXXXXX'); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } i get
- 2 replies
-
- php 5.3.28
- mssql
-
(and 3 more)
Tagged with:
-
Good afternoon, I am working on a project that gives the user a data table and a google chart (using the api) based on what the user selects for a <select> <option>. Index.PHP code: <form> <select name="users" onchange="showUser(this.value);drawChart();"> <option value=""> Select a Metal: </option> <?php //connection details $query = "SELECT TOP(31) tblMetalPrice.MetalSourceID, tblMetalSource.MetalSourceName from tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID=tblMetalSource.MetalSourceID ORDER BY tblMetalPrice.DateCreated DESC "; $result = sqlsrv_query( $conn, $query); while( $row = sqlsrv_fetch_object ($result)) { echo "<option value='".$row->MetalSourceID ."'>". $row->MetalSourceName ."</option>"; } sqlsrv_close( $conn); ?> </select> </form> <div id="chart_div"></div> <div id="txtHint"><b>Past metal information will be generated below.</b></div> this works fine and generates the list in the select option dropdown Script to get table contents: <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","scripts/gettabledata001.php?q="+str,true); xmlhttp.send(); } </script> this also works fine and generates the table contents based on 'q' value from the select dropdown. Google API script: <script type="text/javascript"> // Load the Visualization API and the piechart,table package. google.load('visualization', '1', {'packages':['corechart']}); google.setOnLoadCallback(drawChart()); function drawChart() { var jsonData = $.ajax({ url: "scripts/getgraphdata.php", dataType:"json", data: "q="+num, async: false }).responseText; // Instantiate and draw our pie chart, passing in some options. var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, {width: 400, height: 240}); } </script> getgraphdata.php script: $q = intval($_GET['q']); ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); $query ="SELECT TOP(30) tblMetalPrice.MetalSourceID, tblMetalPrice.DateCreated, tblMetalPrice.UnitPrice, tblMetalPrice.HighUnitPrice, tblMetalSource.MetalSourceName FROM tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID = tblMetalSource.MetalSourceID WHERE tblMetalPrice.MetalSourceID = '".$q."' ORDER BY tblMetalPrice.DateCreated DESC"; $result = sqlsrv_query($conn, $query); echo "{ \"cols\": [ {\"id\":\"\",\"label\":\"Date\",\"pattern\":\"\",\"type\":\"string\"}, {\"id\":\"\",\"label\":\"Unit Price\",\"pattern\":\"\",\"type\":\"number\"} ], \"rows\": [ "; $total_rows = sqlsrv_num_rows($result); $row_num = 0; while($row = sqlsrv_fetch_object($result)){ $row_num++; if ($row_num == $total_rows){ echo "{\"c\":[{\"v\":\"" . $row->DateCreated->format('d-m-Y') ."\",\"f\":null},{\"v\":" . $row->UnitPrice . ",\"f\":null}]}"; } else { echo "{\"c\":[{\"v\":\"" . $row->DateCreated->format('d-m-Y') ."\",\"f\":null},{\"v\":" . $row->UnitPrice . ",\"f\":null}]}, "; } } echo " ] }"; sqlsrv_close( $conn); When ever i try these they don't work the getgraphdata.php scripts runs fine the issue I believe but may be totally wrong may be done to the google api script that should generate the chart but doesn't. Can anyone help here I've been trying to sort this for a few days now and losing confidence in myself rapidly. Thanks Kris
- 3 replies
-
- google charts
- mssql
-
(and 3 more)
Tagged with: