这是我的代码。
我想显示名字,姓氏和电话号码,但我的代码只显示1个号码
我想通过for
和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;
}
}
}
?>
答案 0 :(得分:0)
像这样更改此代码,因为foreach中的返回将在第一轮返回
foreach($results as $row){
$tel[$counter] = $row->Telephone;
$counter++;
}
return $tel;