|
The query command is returning a boolean "false", to indicate no record was found. You need to test for that possibility before assuming that you have a valid record. See PHP: mysqli::query - Manual[^].
|
|
|
|
|
Thank ya for the insight..I greatly appreciate it
|
|
|
|
|
Your pretty far off with your code, and I'm not sure which version of PHP your using. Plus your code is very primitive and not object oriented like for PHP versions 7 and up. You have to create a db connector as a class and call that db connector. Then create a query . Next run that query with the db connector which creates a result . The result can be false if nothing comes back, or can be a array of records in which you fetch them. Finally you call that array that was returned and convert them to rows .
I packed the rows into an object that I created, and return the object instead of an array. The code your writing is very the year 2000, and is quite old and outdated. Nobody in western democracies are writing code like that anymore.
PHP 7.4 example, what you should be learning.
Hope that helps you, and PHP Storm by Jet Brains is the preferred editor or IDE for PHP.
<br />
public static function getUsers(): Users {
$users = new Users();
$query = "
SELECT
uid,
Username<br />
FROM [user]
WHERE User_type <> 'xxxxxxx'
ORDER BY Username";
$conn = DbConnectRepository::createConn();
$result = sqlsrv_query($conn, $query) or die(" getUsers " . LINE . " - " . $query . ' - ' . print_r(sqlsrv_errors()));
while ($row = sqlsrv_fetch_array($result)) {
$user = new User();
$user->setUserId($row[0]);
$user->setUserName($row[1]);<br />
$users->add($user);
}
return $users;
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hey there,
My first time posting on this forum.
I've written and reformed this database a lot over the years. It's written as a C# class library powered by SQLite. It was called metastrings, but that's a dumb name, and I've boiled it down to four operations - UPSERT, SELECT, DELETE, DROP - so 4db made more sense:
GitHub - michaelsballoni/4db: Simple database for high productivity and ease of use
To see how it works, check out the carsdb sample:
4db/carsdb · GitHub
I'd like to get some feedback on the general premise and the implementation.
Thanks, -Michael
|
|
|
|
|
How to write stored procedure in mysql workbench. SELECT, INSERT, UPDATE,DELETE
|
|
|
|
|
|
|
delete
modified 12-Oct-21 8:36am.
|
|
|
|
|
Please don't repost if your question does not appear immediately: all of these went to moderation and required a human being to review them for publication. In order to prevent you being kicked off as a spammer, both had to be accepted, and then I have to clean up the spares. Have a little patience, please!
I've deleted the spare.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
<pre lang="VB">Dim strSql As String = "SELECT DISTINCT Orders.OrderId, Orders.ClientId, OrderDate, DueDate, SubTotal, SalesTax, CityTax, LaborTax, Discount, Delivery, OrderTotal,
OrderDetails.ItemId, OrderDetails.Category, OrderDetails.Description, OrderDetails.Qnty, OrderDetails.Unit, OrderDetails.RetailPrice, OrderDetails.Total, (Select MIN (OrderPymts.PrevBal)) As PrevBal, (Select MAX(OrderPymts.PaymentDate)) As PaymentDate,
(Select MIN (OrderPymts.Payment)) As Payment, (Select MIN (OrderPymts.Balance)) As Balance, OrderPymts.Terms, (Select MAX(OrderPymts.PaymentId)) As PaymentId, Clients.Name,
Clients.Address + ' ' + Clients.City + ', ' + Clients.State + '. ' + Clients.Zip AS ClientsAddress,
'Phone : ' + Clients.Phone + ' Fax : ' + Clients.Fax + ' CellPhone : ' + Clients.CellPhone + ' Email : ' + Clients.Email As ContactInfo, Clients.Since
FROM Orders, Clients
INNER JOIN OrderDetails ON OrderDetails.OrderId = Orders.OrderId
INNER JOIN Clients ON Orders.ClientId = Clients.ClientId
INNER JOIN OrderPymts ON OrderPymts.OrderId = Orders.OrderId
WHERE (Orders.OrderId = @OrderId)"</pre>
I'm having trouble with this statement. This statement is used to call the records in the invoice. Odd since I have 2 records, One with multiple items and only 1 payment and it displays fine. The other record with multiple detail items and multiple payments displays the items twice on the invoice report and shows the first payment record instead of the latest payment record. There are 3 tables, Orders, OrderDetails, and OrderPymts. So I'm trying to query from all three tables based on the orderId.
Any Help would be greatly appreciated.
-- modified 10-Oct-21 22:16pm.
|
|
|
|
|
We can't see the structure of your tables, nor the data they contain.
But what you've described is the expected result of joining multiple records - if you have three lines and two payments for one order, and join them on the order ID, you will get six records in the output.
Visual Representation of SQL Joins[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How can I post an Image of the Invoice and Tables ?
|
|
|
|
|
You can't.
You can create a small reproduction of your tables using sample data as a SQL Fiddle[^], and post the link to that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A real image would be rather weird
What's the structure, and some example data. If you can provide those, then we can "try" your code with your examples and play a bit with it. Without that, we'd have to guess.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The problem was in the OrderPymts table. I used the PaymentId to resolve the issue. Now it displays the right number of items in the Invoice.
|
|
|
|
|
So, I'm trying to import Semicolon separated files into SQL Server.
The files are in codepage 1252 and are "Text Qualified" with a broken bar ¦
In the preview everything looks fine, but in the imported Tables all text fields looks like this: ¦text¦
This wouldn't be a big problem if it wasn't for the fact that some text fields contain semicolons.
Then some columns reads: ¦beginning of text , and the next one: end of text¦ , and the last one might look like this: ¦¦;¦¦
If I'm saving the import as a dtsx package and open it in visual studio, the problem remains the same.
Is this a known bug or am I doing something wrong?
Any solutions that doesn't require me to create my own CSV-import?
|
|
|
|
|
Why are you using a text qualifier because it is doing exactly what you asked it to.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I thought the purpose of the text qualifier is to tell the parser that the following chunk of text is in one field despite containing a column delimiter
Anyway, If I don't use a text qualifier, it behaves exactly the same, except that the preview now shows the same as the data in the tables.
The data our supplier sends looks like this:
¦Column1¦;¦Column2¦;¦Column3¦;¦Column4¦
¦Text¦;¦Some other text¦;¦Text¦;¦Also text¦
¦¦;¦More text¦;¦Text with a ; embedded¦;¦¦
¦etc.¦;¦etc.¦;¦etc.¦;¦...¦
What I want in the database is this:
Column1 Column2 Column3 Column4
Text Some other text Text Also text
More text Text with a ; embedded
etc. etc. etc. ...
What I get is this:
Column1 ;Column2 Column3 Column4
¦Text¦ ¦Some other text¦ ¦Text¦ ¦Also text¦
¦¦ ¦More text¦ ¦Text with a embedded¦;¦¦
¦etc.¦ ¦etc.¦ ¦etc.¦ ¦...¦
|
|
|
|
|
Sorry to ask what might be a stupid question, You say the file is "Text Qualified" but have you actually set the "Text Qualifier" field in the import config?
|
|
|
|
|
There are no stupid questions. (Well ok, but this wasn't one )
I have set the "Text qualifier" field in the General page to: ¦
In the advanced page I have set every field to TextQualified = True
What gets at me is that this seem to work as expected in the preview tab.
|
|
|
|
|
Quote: What gets at me is that this seem to work as expected in the preview tab. That would have me tearing my hair out! At which stage I would probably try a reinstall
However, weird as this may sound (is anything truly weird when it comes to Microsoft??) have you tried not setting TextQualified on the individual fields? (i.e. just on the General page). I'm probably just grasping at straws tbh
|
|
|
|
|
Yes I have.
Both suggestions.
It also behaves the same if I create an SSIS project in Visual Studio.
|
|
|
|
|
I just found out that opening the files in Notepad++ as codepage 1252 and saving them as UTF8, and then change the import from 1252 to UTF8, fixes the problem.
I'm putting this down as a bug from MS. (That probably won't ever be fixed)
The question is, what is the best way to fix it?
For a one off I will just open and save all the files and import them as UTF8.
But this will be a weekly import later on, preferably run as an SSIS package.
|
|
|
|
|
Have you tried using the "Import Flat File" wizard, instead of the "Import/Export Data" wizard? It's supposed to be better at this sort of thing...
Import Flat File to SQL - SQL Server | Microsoft Docs[^]
Otherwise, you might need to resort to Powershell or C#.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, the "Import Flat File" wizard doesn't recognize the Text qualifier at all.
Meanwhile I have noticed that if I open a file in Notepad++ as codepage 1252 and saving it as UTF8, and then change the import from 1252 to UTF8, it works as advertised.
This is OK as a one off, but what is the best way to change the file encoding that can be run from inside an SSIS package?
|
|
|
|