PHP和表格式

时间:2014-02-18 17:12:42

标签: php joomla

大家好,我有以下php,我想在自己的表行中设置每个echo命令,但我有问题....某处......

<?php
$db=JFactory::getDBO();
$q = "select * from #__jbjobs_employer where user_id=".$job->employer_id;
$db->setQuery($q);
$employer_record = $db->loadObject();
echo ($employer_record->show_addr == 'y')? "Address: ".$employer_record->street_addr.', '.$employer_record->city.', '.$employer_record->state : JText::_('JBJOBS_NOT_DISPLAYED').'<br>';
echo ($employer_record->show_phone == 'y')? "Phone: ".$employer_record->primary_phone : JText::_('JBJOBS_NOT_DISPLAYED').'<br>';  
echo ($employer_record->show_fax == 'y')? "Fax: ".$employer_record->fax_number : JText::_('JBJOBS_NOT_DISPLAYED').'<br>';  
$u = JFactory::getUser($job->employer_id);
echo ($employer_record->show_email == 'y')? "Email:".$u->email : JText::_('JBJOBS_NOT_DISPLAYED');                                              
?>

我尝试使用下面的代码片段,但鉴于我对PHP一无所知,所有内容都显示在一行中,没有看到任何表格

<?php
$db=JFactory::getDBO();
$q = "select * from #__jbjobs_employer where user_id=".$job->employer_id;
$db->setQuery($q);
$employer_record = $db->loadObject();                                           
            '<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
               <td>';echo ($employer_record->show_addr == 'y')? "".$employer_record->street_addr : JText::_('JBJOBS_NOT_DISPLAYED').'</tr>
              <tr>
                <td>';
echo ($employer_record->show_location == 'y')? "".$employer_record->city.', '.$employer_record->state : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';
echo ($employer_record->show_phone == 'y')? "".$employer_record->primary_phone : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';  
echo ($employer_record->show_fax == 'y')? "".$employer_record->fax_number : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';  
$u = JFactory::getUser($job->employer_id);
echo ($employer_record->show_email == 'y')? "".$u->email : JText::_('JBJOBS_NOT_DISPLAYED');'</td>
          </td>
              </tr>
          </table>'
?>
有人可以伸出援助之手吗?感谢!!!!

4 个答案:

答案 0 :(得分:1)

首先,您应该像使用最新的Joomla编码标准一样编写查询

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'))
      ->from($db->quoteName('#__jbjobs_employer'))
      ->where($db->quoteName('user_id') . ' = '. $db->quote($job->employer_id);
$db->setQuery($query);
$employer_record = $db->loadObject(); 

然后要显示它,您需要在表之前使用echo,如下所示:

echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">

另外,在旁注中,您需要关闭第一组结果的开头td,因此请更改此内容:

JText::_('JBJOBS_NOT_DISPLAYED').'</tr>

到此:

JText::_('JBJOBS_NOT_DISPLAYED').'</td>

希望这有帮助

答案 1 :(得分:0)

 echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
 ^^^^---you forgot this

答案 2 :(得分:0)

试试这个,你错过了第6行的echo

<?php
$db=JFactory::getDBO();
$q = "select * from #__jbjobs_employer where user_id=".$job->employer_id;
$db->setQuery($q);
$employer_record = $db->loadObject();                                           
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
               <td>';echo ($employer_record->show_addr == 'y')? "".$employer_record->street_addr : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr><td>';
echo ($employer_record->show_location == 'y')? "".$employer_record->city.', '.$employer_record->state : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';
echo ($employer_record->show_phone == 'y')? "".$employer_record->primary_phone : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';  
echo ($employer_record->show_fax == 'y')? "".$employer_record->fax_number : JText::_('JBJOBS_NOT_DISPLAYED').'</td>
              </tr>
              <tr>
                <td>';  
$u = JFactory::getUser($job->employer_id);
echo ($employer_record->show_email == 'y')? "".$u->email : JText::_('JBJOBS_NOT_DISPLAYED');'</td>
          </tr>
          </table>'
?>

答案 3 :(得分:0)

所以这就是我所做的并且有效:

<?php
echo "<table width='100%' border='0'>";
$db=JFactory::getDBO();
$q = "select * from #__jbjobs_employer where user_id=".$job->employer_id;
$db->setQuery($q);
$employer_record = $db->loadObject();
echo "<tr><td>";
echo ($employer_record->show_addr == 'y')? "".$employer_record->street_addr : JText::_('JBJOBS_NOT_DISPLAYED');
echo "</td></tr>";
echo "<tr><td>";
echo ($employer_record->show_location == 'y')? "".$employer_record->city.', '.$employer_record->state : JText::_('JBJOBS_NOT_DISPLAYED');
echo "</td></tr>";
echo "<tr><td>";
echo ($employer_record->show_phone == 'y')? "".$employer_record->primary_phone : JText::_('JBJOBS_NOT_DISPLAYED');
echo "</td></tr>";
echo "<tr><td>"; 
echo ($employer_record->show_fax == 'y')? "".$employer_record->fax_number : JText::_('JBJOBS_NOT_DISPLAYED');
$u = JFactory::getUser($job->employer_id);
echo "</td></tr>";
echo "<tr><td>";
echo ($employer_record->show_email == 'y')? "".$u->email : JText::_('JBJOBS_NOT_DISPLAYED');
echo "</table>";
?>