duankui1532 2014-07-16 22:59
浏览 49
已采纳

PHP SQL Joomla存储表将两列放入数组并稍后回显它们

So I have a simple table with two columns. The table is called "mytable" and the columns are "product" and "id". The table has about 12 entries.

            $db = JFactory::getDbo();
            $query = "SELECT * FROM mytable";
            $db->setQuery($query);
            $results = $db->loadObjectList();

So I've gotten this far querying successfully but I want to call back the results of each row. That's the part I am stuck on. I need to store this into an array so I can later make a while loop spitting out each row. Also I cannot echo it right underneath that code. This needs to be stored in an array that is then pulled from another page and then I spit out each row. Thanks!

  • 写回答

2条回答 默认 最新

  • doukan3504 2014-07-17 06:21
    关注

    Try this,

            $db = JFactory::getDbo();
            $query = "SELECT * FROM mytable";
            $db->setQuery($query);
            $results = $db->loadObjectList();
            echo '<pre/>'
            print_r($results);//the resulted array is already in this variable you can iterate it later with foreach loop.
    

    for looping and printing

    foreach($results as $key=>$value){
     echo 'Product-->'.$value->product;
     echo 'ID-->'.$value->id;
    }
    

    check the Joomla DB query for more details.

    Hope it helps..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?