[英]get the result of select query with different database in codeigniter
[英]how to use nested select query in codeigniter to get different result by each query
`
$poplrRec = mysql_query("SELECT * FROM ".ADD_RECIPE." ORDER BY POPULARITY DESC LIMIT 4");
while($poplrRec1=mysql_fetch_array($poplrRec))
{
$likecount=mysql_query("SELECT RECIPE_ID, COUNT(RECIPE_ID) FROM ".RECIPE_LIKE." WHERE RECIPE_ID=".$poplrRec1['RECIPE_ID']);
while($b=mysql_fetch_array($likecount))
{
$cmnt=mysql_query("SELECT RECIPE_ID, COUNT(RECIPE_ID) FROM ".RECIPE_CMMNT." WHERE RECIPE_ID=".$poplrRec1['RECIPE_ID']." AND TYPE=0");
while($c=mysql_fetch_array($cmnt))
{
}} } `
您好,在这里我使用核心php while循环和MySQL查询,因此我必须在codeigniter的MVC结构中使用这些类型的查询。 就像这里,我希望将每个查询的结果单独用于mvc结构。 每个查询提供一些需要在相关地方使用的数据。 请给我建议我如何在codeigniter或mvc结构中实现这些类型的php查询。
$result=$this->db->query("select * from tableName");
foreach($result->result() as $row){
// $row has the associative array
// you can again query the database with $this->db->query
}
尝试编写查询以下格式
$query = $this->db->get('vehicles_types');
$result = $query->result_array();
// loop through the types e.g. the parents
foreach( $result as $key => $row )
{
// add the "examples" e.g. the children to the result array
$query = $this->db->get_where('vehicles',array('type'=>$row['id']));
$row['examples'] = $query->result_array();
$result[$key] = $row;
}
return $result;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.