dongyuan2652 2014-02-21 14:15
浏览 17

如何在joomla模块中检索和显示数据的结果集。

This is my code .

I want to display the firstname, lastname and phone number, but my code is only displaying 1 number

I want get and show a series of numbers from the database with for and while.

mod_phonebook.php

<?php
defined( '_JEXEC' ) or die('Restricted access');
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::root().'modules/mod_phonebook/css/main.css');
require_once(dirname(__FILE__).DS.'helper.php');

if(isset($_POST['search'])){

    $jinput = JFactory::getApplication()->input;
    $name = $jinput->get('name','','STRING');
    $lname = $jinput->get('lname','','STRING');
    $tell = $jinput->get('tell','','INT');
    if(myphonebook::searchdata($name,$lname,$tell)) 
    {
        echo "<p class='lbl'>$name:نتایج جستجو شامل</p>";
        echo "<p class='lbl'>شماره پیدا شده=".myphonebook::searchdata($name,$lname,$tell).'</p><br>';
    }
    else
    {
        echo "شماره ای به این نام پیدا نشد";    
    }

}
else
{
    require(JMOduleHelper::getLayoutPath('mod_phonebook')); 
}

?>

helper.php

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

class myphonebook{
   public static function searchdata($name,$lname,$tell){

       $db = JFactory::getDBO();
       $query = "SELECT * from `phonebook` WHERE `name` ='$name' or  `Family`='$lname'  or  `Numberofroom`='$tell'";
       $db->setQuery($query);
       $results = $db->loadObjectList();
       if($db->query())
       {                
           foreach($results as $row){
               $tel = $row->Telephone;  
               return $tel;
               $counter++;
           }
       }    
       else
       {
           return false;
       }

   }
}
?>
  • 写回答

1条回答 默认 最新

  • dpw5865 2014-02-21 15:30
    关注

    change this code like this,because return inside foreach will be returned in first turn

     foreach($results as $row){
                       $tel[$counter] = $row->Telephone;  
    
                       $counter++;
                   }
     return $tel;
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度