2015-10-22 26 views
-2
$resturant_category_product_query = "SELECT * FROM bb_product p WHERE p.resturant_category_id ='$resturant_category_id'"; 
foreach ($resturant_category_product_query as $resturant_category_product) { 
     $resturant_category_product_data[] = array(
      'resturant_category_id' =>$resturant_category_product['resturant_category_id'], 
     ); 
} 
+0

你只需要看看[mysqli](http://php.net/manual/it/book.mysqli.php)的文档,或者一些教程。 – Federkun

+0

如何获得$ resturant_category_product_data []值 – Hitesh

+0

您需要执行查询,然后检索每个返回的行。你的代码只是为查询字符串设置一个变量,然后尝试将该字符串视为一个数组。 – Kickstart

回答

0

简单的例子: -

<?php 
$mysqli_connection = new mysqli("localhost", "my_user", "my_password", "world"); 

$sql = "SELECT * 
     FROM bb_product p 
     WHERE p.resturant_category_id ='".$mysqli_connection->->real_escape_string($resturant_category_id)."'"; 

if ($result = $mysqli_connection ->query($sql)) 
{ 
    while($row=$result->fetch_assoc($result)) 
    { 
     $resturant_category_product_data[] = array('resturant_category_id'=>$row['resturant_category_id']); 
    } 
    $result->close(); 
} 

此创建使用库MySQLi数据库的连接的对象。

然后它设置一个它想要执行的SQL的字符串。请注意,它使用连接对象来使用该类来转义该字符串(以防止SQL注入)。

该字符串被连接对象的查询方法使用,返回结果对象。

然后,它执行一个WHILE循环来自结果对象的每个返回行(每行由fetch_assoc作为关联数组返回)。请注意,返回的行放入$ row变量中。