在PHP if语句中连接SQL查询

时间:2017-09-21 14:21:06

标签: php sql

我试图通过PHP if语句连接SQL查询,如下所示:

class MarkerModel: NSObject, GMUClusterItem {
var position: CLLocationCoordinate2D
var name: String

init(position: CLLocationCoordinate2D, name: String) {
    self.position = position
    self.name = name
}
}


override func viewDidLoad() {
super.viewDidLoad()

mapView = GMSMapView(frame: view.frame)
mapView.camera = GMSCameraPosition.camera(withLatitude: 13.756331, longitude: 100.501765, zoom: 12.0)
mapView.mapType = .normal
mapView.delegate = self
view.addSubview(mapView)

if isClustering {
    var iconGenerator: GMUDefaultClusterIconGenerator!
    if isCustom { // Here's my image if the event are clustered
        var images: [UIImage] = [UIImage(named: "m1.png")!, UIImage(named: "m2.png")!, UIImage(named: "m3.png")!, UIImage(named: "m4.png")!, UIImage(named: "m5.png")!]
        iconGenerator = GMUDefaultClusterIconGenerator(buckets: [5, 10, 15, 20, 25], backgroundImages: images)
    } else {
        iconGenerator = GMUDefaultClusterIconGenerator()
    }

    let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm()
    let renderer = GMUDefaultClusterRenderer(mapView: mapView, clusterIconGenerator: iconGenerator)

    clusterManager = GMUClusterManager(map: mapView, algorithm: algorithm, renderer: renderer)

} else {
}
}

func addMarkers(cameraLatitude : Float, cameraLongitude : Float) {
    let extent = 0.01
    for index in 1...clusterItemCount {
        let lat = cameraLatitude + extent * randomScale()
        let lng = cameraLongitude + extent * randomScale()
        let name = "Item \(index)"

        let position = CLLocationCoordinate2DMake(lat, lng)

        let item = MarkerModel(position: position, name: name)
        item.icon = #imageLiteral(resourceName: "marker")
        clusterManager.add(item)
    }
     clusterManager.cluster()
        clusterManager.setDelegate(self, mapDelegate: self)
}

func randomScale() -> Double {
    return Double(arc4random()) / Double(UINT32_MAX) * 2.0 - 1.0
}

func renderer(_ renderer: GMUClusterRenderer, markerFor object: Any) -> GMSMarker? {

    let marker = GMSMarker()
    if let model = object as? MarkerModel {
         // set image view for gmsmarker
    }

    return marker
}

func clusterManager(_ clusterManager: GMUClusterManager, didTap cluster: GMUCluster) -> Bool {
    let newCamera = GMSCameraPosition.camera(withTarget: cluster.position, zoom: mapView.camera.zoom + 1)
    let update = GMSCameraUpdate.setCamera(newCamera)
    mapView.moveCamera(update)
    return false
}

从我执行的故障排除中,问题是在连接的SQL查询中的if语句中的某处

$sqlProdPage = "SELECT DISTINCT productpts.ProductID,product.ProductTitle,productsubtype.ProductSubtype,producttype.ProductType,product.ProductPrice,product.ProdDiscount,product.ProductImage,
        product.ProductDescription,product.ProdFeatured,product.ProdQTY,product.ProdAddDesc 
        FROM productpts 
        INNER JOIN product ON productpts.ProductID=product.ProductID 
        INNER JOIN productsubtype ON productpts.ProductSubtypeID=productsubtype.ProductSubtypeID 
        INNER JOIN producttype ON productpts.ProductTypeID=producttype.ProductTypeID  
        WHERE product.Archive='0'";

$prodType_id=(($_POST['product'] != '')?sanitize($_POST['product']):'');
if(!empty($prodType_id)){
    $sqlProdPage.= " AND ProductTypeID='{$prodType_id}'";//echo $prodType_id;die();
}

有人能给我一个关于如何连接它的建议吗?

Results in chrome developer tools

但是内联37我有以下错误:

  

警告:mysqli_fetch_assoc()期望参数1为mysqli_result,   第37行的C:\ xampp \ htdocs \ aresV2 \ search.php中给出的布尔值

第36和37行:

 $sqlProdPage.= " AND ProductTypeID='{$prodType_id}'"

1 个答案:

答案 0 :(得分:0)

问题是ProductTypeID是在多个表中定义的,因此不确定应该使用哪个。

$sqlProdPage.= " AND productpts.ProductTypeID='{$prodType_id}'";

应该做的伎俩(假设它来自productpts表)。