角材料.如何将参数传递给PHP? [英] Angular Material. How do I pass a parameter to PHP?

查看:70
本文介绍了角材料.如何将参数传递给PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Angular Material复制一个已经使用HTTP/JavaScript等运行了两年的应用程序.该应用程序可以称为具有远程服务器上MySQL数据库上的CRUD操作的数据库类型应用程序在应用程序和数据库之间使用PHP.

I am trying to replicate an app in Angular Material that I have had running for a couple years with HTTP/JavaScript etc. The app is what could be called a database type app with CRUD operations on a MySQL database on a remote server which uses PHP between the App and the Database.

从服务器中以JSON返回的几张表的范围受到JavaScript发送的参数的限制,然后由PHP接收,并在Select语句的where子句中使用,例如以下代码段:

Several of the tables which are returned from the server in JSON are range limited by a parameter sent from the JavaScript, and then received by the PHP, and used in the where clause of the Select statement like this code snippet:

$registration      = $_POST['REGISTRATION'] ;
$query  = "SELECT sysid, REGISTRATION, TYPE, COMPONENT, SERIAL, PART_NUMBER FROM status_hours WHERE REGISTRATION='$registration' ";

此HTTP/JavaScript/PHP代码运行正常,但是我想在Angular Material中复制该应用程序.

This HTTP/JavaScript/PHP code is working perfectly, however I would like to replicate the app in Angular Material.

使用Angular Material,我可以完美地以JSON检索记录器,但是问题是我无法发送参数并使它正常工作,因此可以在PHP的WHERE子句中使用它.

With Angular Material I can retrieve recors in JSON perfectly, but the problem is that I can not send a parameter and get it working so that it can be used in the WHERE clause in the PHP.

这是应用程序上的Type Script代码,可从服务器获取行表.

Here is the Type Script code on the app which gets a table of rows from the server.

const url     = 'http://mydatabase.com/angular/php/status_hours.php'               ;
    const options = { params: new HttpParams().set('REGISTRATION', this.REGISTRATION) }   ;
    this.http.get<Hours[]> (url, options)
    .subscribe(hours => 
    {
        console.log(hours)            ;
        this.dataSource.data = hours  ; 
    } )  ;

这是我尝试过的PHP代码,用于接收称为REGISTRATION的参数,以便可以在WHERE语句中使用它.

Here is the PHP code I have tried, to receive the parameter which is called REGISTRATION so that it can be used in the WHERE statement.

$postdata   = file_get_contents("php://input");
$request    = json_decode($postdata);
$registration   = $request->REGISTRATION;

问题是Angular应用程序没有发送参数,或者PHP没有接收到该参数,因此可以在WHERE子句中使用它. 我可以出于汇总目的进行硬编码,$ registration ='hardCodedData';它将返回有效的JSON数据.

The problem is either the parameter is not being sent by the Angular app, or it is not being received by the PHP so that it can be used in the WHERE clause.
I can hardcode for sumulation purposes, $registration = 'hardCodedData' ; and it will return valid JSON data.

谢谢您的帮助.

推荐答案

这里是我用来使我能够传递多个参数的链接.当然,同样的PHP代码也适用.

Here is a link which I have used to enable me to pass multiple parameters. The same PHP code applies of course.

Angular 4 HttpClient查询参数

这篇关于角材料.如何将参数传递给PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆