PHP:从*奇怪的* MySQL 数据库获取数据

发布于 2024-12-02 20:02:22 字数 1745 浏览 1 评论 0原文

我有一个来自 VoIP 公司的用 C#/.NET 编写的闭源软件,该软件无法自定义,并且希望使用 PHP 创建自定义前端。我获得了数据库的访问权限,现在看看它是如何运作的。我想向用户输出他的“快速拨号”号码,但遇到问题解决。以下是表格结构:

'customer' table
+-------------------------------------------------------------------------+
| CustomerID | FirstName | LastName | Balance | Email | Password | Status |
|-------------------------------------------------------------------------|
| 1          | Homer     | Simpson  | 5.00    | [email protected] | iheartm  | 1      |
| 2          | Marge     | Simpson  | 3.00    | [email protected] | ihearth  | 1      |
+-------------------------------------------------------------------------+

'calls' table
+------------------------------------------------------------------------+
| CallID | Caller  | Callee  | ServiceID  | Duration | Cost | CustomerID |
|------------------------------------------------------------------------|
| 1      | 1234567 | 7654321 | 30         | 60       | 1.00 | 1          |
| 2      | 7654321 | 1234567 | 45         | 120      | 2.00 | 2          |
+------------------------------------------------------------------------+

'ani' (speed-dial) table
+---------------------------------------+
| PhoneNumber | ServiceID | ContactName |
|---------------------------------------|
| 1234567     | 45        | Homer       |
| 7654321     | 30        | Marge       |
+---------------------------------------+

如您所见,1234567 是 Homer 的电话号码,在 Marge 的快速拨号列表中,7654321 是 Marge 在 Homer 的列表中的号码。就像我可以使用 $current_user['Balance']; 登录时提取客户的余额一样,有没有办法在 PHP 中向用户显示他的“快速拨号”号码?

I have a closed-source software written in C#/.NET from a VoIP company which is impossible to customize and wanted to create custom front-end using PHP. I gained access to the database and now see how it functions. I wanted to output the user his 'speed dial' numbers, but having issue solving it. Here are the tables structures:

'customer' table
+-------------------------------------------------------------------------+
| CustomerID | FirstName | LastName | Balance | Email | Password | Status |
|-------------------------------------------------------------------------|
| 1          | Homer     | Simpson  | 5.00    | [email protected] | iheartm  | 1      |
| 2          | Marge     | Simpson  | 3.00    | [email protected] | ihearth  | 1      |
+-------------------------------------------------------------------------+

'calls' table
+------------------------------------------------------------------------+
| CallID | Caller  | Callee  | ServiceID  | Duration | Cost | CustomerID |
|------------------------------------------------------------------------|
| 1      | 1234567 | 7654321 | 30         | 60       | 1.00 | 1          |
| 2      | 7654321 | 1234567 | 45         | 120      | 2.00 | 2          |
+------------------------------------------------------------------------+

'ani' (speed-dial) table
+---------------------------------------+
| PhoneNumber | ServiceID | ContactName |
|---------------------------------------|
| 1234567     | 45        | Homer       |
| 7654321     | 30        | Marge       |
+---------------------------------------+

As you can see, 1234567 is Homer's phone number and in Marge's speed dial list and 7654321 is Marge's number in Homer's list. Just like I can pull up customer's balance when logged in using: $current_user['Balance'];, is there way to show user his 'speed dial' numbers in PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡写薰衣草的香 2024-12-09 20:02:22

这个请求没有达到你想要的效果?

SELECT 
    a.CustomerID, a.FirstName, a.LastName, a.Balance, a.Email, a.Status,
    b.ServiceID,
    (SELECT GROUP_CONCAT(CONCAT(ContactName,':',PhoneNumber)) FROM ani GROUP BY PhoneNumber WHERE ServiceID = b.ServiceID)
FROM customer a
LEFT JOIN calls b ON a.CustomerID = b.CustomerID
WHERE a.CustomerID = 'replace_by_customer_id'

这应该获取客户表的数据,以及连接的客户的快速拨号号码所产生的字符串。

我假设一个 customerid 对应于在呼叫中找到的一个唯一的 serviceid,并且表 ani 中的 serviceid 指示快速拨号号码的所有者。但这似乎是一个奇怪的架构,因此您应该向我们提供有关表的更多数据或信息......

This request doesn't achieve what you want ?

SELECT 
    a.CustomerID, a.FirstName, a.LastName, a.Balance, a.Email, a.Status,
    b.ServiceID,
    (SELECT GROUP_CONCAT(CONCAT(ContactName,':',PhoneNumber)) FROM ani GROUP BY PhoneNumber WHERE ServiceID = b.ServiceID)
FROM customer a
LEFT JOIN calls b ON a.CustomerID = b.CustomerID
WHERE a.CustomerID = 'replace_by_customer_id'

This should fetch the data of the customer table, plus a string that results from concatenating the speed-dial numbers of the customer connected.

I assume that a customerid corresponds to one unique serviceid found in calls, and the serviceid in the table ani indicates the owner of the speed-dial number. But it seems a weird architecture, so you should give us more data or informations about the tables...

内心荒芜 2024-12-09 20:02:22

ServiceID 与客户中的特定条目之间似乎缺少关系。调用表提供这种关系似乎很奇怪,它应该仅仅使用它。

仅使用您提供的信息,您只能加入呼叫以将 CustomerID 与我认为您拥有的 ServiceID 链接起来。查询如下所示:

SELECT ContactName, PhoneNumber FROM ani
LEFT JOIN calls ON ani.ServiceID=calls.ServiceID
WHERE calls.CustomerID=xxx

There seems to be a missing relation from ServiceID to a specific entry in customer. It would seem strange that the calls table would provide that relation, it should merely use it.

With only the information you supplied you can only join calls to link the CustomerID with the ServiceID which I suppose you have. The query would look like this:

SELECT ContactName, PhoneNumber FROM ani
LEFT JOIN calls ON ani.ServiceID=calls.ServiceID
WHERE calls.CustomerID=xxx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文