I’m currently use CustomerID = <?php $current_user->user_login ?> to get invoice data for the current user. We recently started adding multiple users that are in the same company and the naming convention is customerID + first 3 digits of their first name.
How would I add a wildcard to the <?php $current_user->user_login ?> ?
It hard to guess without seeing your whole query but if I understand you correctly then I think you might want to use something like this:
WHERE CustomerID = <?php substr($current_user->user_login, 0, -3) ?>
This is assuming that your CustomerID is something like 90210 and my user login might be 90210eli
if I’m wrong about that then please give more details and an example query so that I can help you further.
The full query with the modification you provided.
select SalesOrderNumber , InvoiceNumber , InvoiceDate , NetAmount, Freight, Tax, InvoiceTotal FROM
Invoiceswhere InvoiceDate BETWEEN DATE(NOW()) – INTERVAL 180 DAY AND DATE(NOW()) and CustomerID = ‘ <?php substr($current_user->user_login, 0, -3) ?>’ order by InvoiceDate desc
When trying to run the query I got this error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘IAMAT” order by InvoiceDate desc’ at line 1
my username is IAMATONE – is lessen by 3
In my scenario The current customerID and username is 90120
the additional usernames would be 90120JAN, 90120FEB, 90120MAR and I want all for users to get access to the invoices that 90120 is able to see.
Thanks for the quick reply.
- This reply was modified 1 year, 2 months ago by onyxtacular.
Ok, I think I must have misunderstood, and unfortunately your further explanation here just got me more confused.
I think you are saying that the usernames would be 90120JAN, 90120FEB, or 90120MAR but the it looks like the value of $current_user->user_login is actually IAMATONE, which doesn’t help you at all.
Where are you getting this “usernames” value from?
What is the value of the CustomerID field for the record that you are looking for?
Also, the error message that you are getting suggests that there is something else fouling up the syntax of your SQL statement and it looks like it has to do with the single-quote marks you are using, they should not be slanted like that in your raw SQL statement but maybe they are not and the WordPress forum just made them slanted to pretty-up your post 🙁
Anyway, I don’t think that those quote marks are actually needed there so try the SQL without them just to see if it fixed it or ifthe error message you get is different.
I just realized that the error might also be caused be the misinterpretation of the last AND as an ambiguous relation to the BETWEEN statement. Try using parentheses, or better yet try switching the statements around, like this:
WHERE CustomerID LIKE <?php substr($current_user->user_login, 0, -3) ?> AND InvoiceDate BETWEEN DATE(NOW()) – INTERVAL 180 DAY AND DATE(NOW())
ORDER BY InvoiceDate DESC
on the last command I received the error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘– INTERVAL 180 DAY AND DATE(NOW()) ORDER BY InvoiceDate DESC’ at line 1
I am sorry the confusion. I neglected to mention I was running the query as the administrator and it really had nothing to do with it save it gave and error where my username was shorten by three characters.
I hope this clears things up:
“In my scenario The current customerID and username is 90120”
the customer id on my local sql system is 90120 and the wordpress username is 90120
The additional usernames on wordpress would be 90120JAN, 90120FEB, 90120MAR and I want all for wordpress users to get access to the invoices that 90120 is able to see including the original wordpress user: 90120
my goal is to have any username with a base of 90120 see the output that username 90120 sees.
- The topic ‘wildcard on username’ is closed to new replies.