小编j.D*_*Doe的帖子

在PHP中将SQL数据库中的约束获取到JSON

假设我具有以下汽车制造商和相应汽车的数据库结构:

制造商:

----------------------------------
| manufacturer | founded_in | id |
|--------------|------------|----|
| Daimler AG   | 1927       | 1  |
| Volkswagen AG| 1937       | 2  |
----------------------------------
Run Code Online (Sandbox Code Playgroud)

汽车:

-------------------------------------
| car     | built_in | manufacturer |
|---------|----------|---------------
| C Class | 1993     | 1            |
| E Class | 1993     | 1            |
| Golf    | 1974     | 2            |
-------------------------------------
Run Code Online (Sandbox Code Playgroud)

idmanufacturers是主键,的manufacturercars具有相应的外键约束。

我想使用PHP产生以下JSON输出json_encode

{
    "manufacturers": {
        "Daimler AG": {
            "founded …
Run Code Online (Sandbox Code Playgroud)

php mysql sql json

3
推荐指数
1
解决办法
60
查看次数

数组中的Typescript元素不可访问

这似乎是一个非常尴尬的问题:

我正在modal.service.ts使用以下代码进行访问: this.modalService.add('test');

我的modal.service.ts样子如下:

import { Injectable } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class ModalService {
    private modals: any[] = [];

    add(modal: any) {
        // add modal to array of active modals
        this.modals.push(modal);
    }

    remove(id: string) {
        // remove modal from array of active modals
        this.modals = this.modals.filter(x => x.id !== id);
    }

    open(id: string) {
        // open modal specified by id
        const modal = this.modals.find(x => x.id === id);
        console.log(this.modals)
        console.log(this.modals[0])
        //modal.open();
    } …
Run Code Online (Sandbox Code Playgroud)

arrays typescript

2
推荐指数
1
解决办法
65
查看次数

SQL从1 x N中选择所有大于

我有桌子booksbookType它们构成1 X n关系。

books

+-----+------------------+----------+-------+
| id  |      title       | bookType | price |
+-----+------------------+----------+-------+
|   1 | Wizard of Oz     |        3 |    14 |
|   2 | Huckleberry Finn |        1 |    16 |
|   3 | Harry Potter     |        2 |    25 |
|   4 | Moby Dick        |        2 |    11 |
+-----+------------------+----------+-------+
Run Code Online (Sandbox Code Playgroud)

bookTypes

+-----+----------+
| id  |   name   |
+-----+----------+
|   1 | Fiction  |
|   2 | Drama    |
| …
Run Code Online (Sandbox Code Playgroud)

mysql sql mariadb

2
推荐指数
1
解决办法
55
查看次数

标签 统计

mysql ×2

sql ×2

arrays ×1

json ×1

mariadb ×1

php ×1

typescript ×1