dongya9904 2017-04-20 23:32
浏览 38

如何在Codeigniter中获得Mysqli_result等价物?

I am working on my first App. Basically, I am trying to integrate a Navigation menu that I have used outside Codeigniter. In a normal PHP app, I have the query as follows (the DB constants and connection are in an includes.php file:

//Table columns: id, page, parent
// Select all from the menu table 
// Define database connection constants
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', 'somepassword');
define('DB_NAME', 'dropdown_menu');

if (!isset($dbc)){
 $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  if (!$dbc) {
    die("Database connection and selection failed: " . mysqli_error());
 }
}

//$result=mysqli_query("SELECT id, label, link, parent FROM menu ORDER BY parent, sort, label");
$query = "SELECT id, label, parent FROM tree_menu ORDER BY parent, id";
$result = mysqli_query($dbc, $query)

or die('Error querying database.');

From that stage, I need to feed the $results variable to mysqli_fetch_assoc() and process things using a while loop, as follows:

while ($items = mysqli_fetch_assoc($result)) {
//some code
}

In codeigniter I can't seem to get results from MySQL in a format equivalent to $results obtained from the above query. I did a var_damp($results), so that I see exactly what $results looks like. This is what I get:

object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(3) ["lengths"]=> NULL ["num_rows"]=> int(13) ["type"]=> int(0) }

I tried returning an object() but it did not work because it does not return an equivalent of mysqli_result which I need to use to generate an hierarchical navigation menu.

My question is: Is it possible to that kind of object in Codeigniter - mysqli_result equivalent?

Any help will be deeply appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?