用php内部连接显示所有帖子

时间:2019-03-20 06:54:42

标签: php mysql if-statement while-loop

因此,我有将这类项目分成几个省的项目。我可以显示该帖子,但是如果有2个或更多帖子,则只能显示1个帖子。这是我的PHP代码

/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2018, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.data.hana;

/**
 * SAP HANA connection parameters.
 *
 * @author Stefan Uhrig, SAP SE
 */
public class HanaConnectionParameters {

    /**
     * SAP HANA connection parameters constructor.
     *
     * @param host The database host.
     * @param instance The database instance.
     * @param database The name of the tenant database. Set to null or empty string if the database
     *     is a single-container system. Set to SYSTEMDB to connect to the system database of a
     *     multi-container system.
     */
    public HanaConnectionParameters(String host, int instance, String database,int port) {
        super();
        this.host = host;
        this.instance = instance;
        this.database = database;
        this.port = port;
    }

    private String host;

    private Integer  instance;

    private String database;

    private Integer port;

    public String getHost() {
        return host;
    }

    public Integer getInstance() {
        return instance;
    }

    public String getDatabase() {
        return database;
    }

    public Integer getPort() {
        return this.port;
    }
    /**
     * Builds a JDBC connection URL.
     *
     * @return Returns the JDBC connection URL corresponding to these parameters.
     */
    public String buildUrl() {

         String url = "jdbc:sap://" + this.host + ":" + this.port;
         return url;

    }
}

我不知道如何使用相同的id_province在我的代码中检索多个帖子。因此,如果有2个帖子具有相同的id_province,我将再次重复,这样它将像我的第一张照片一样检索。谢谢

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

首先,我建议您使用mysqli_query()用户,因为MySQL函数已被弃用。

根据您的代码,您需要将查询分为两部分

  

1)从第一个表获取数据

     

2)根据id从第二个表中获取数据

现在,根据结果,您可以根据需要显示div。

$posts=mysql_query("select * from provinces");


while($ps3=mysql_fetch_array($posts)){
        while($result=mysql_fetch_array(mysql_query('select * from table2 where id ='.$ps3['id']))){
            // do code here
          }
 }