简体   繁体   中英

How to retrieve and show resultset of data in a joomla module.

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;
       }

   }
}
?>

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM