2014-02-18 119 views
-1

大家好,我有以下的PHP的,我想在自己的錶行來設置每個echo命令,但我有問題....某處....PHP和表格式

<?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>' 
?> 

能有人伸出援助之手嗎?謝謝!!!!

+0

你錯過了第6行的'echo'嗎?我的信息顯示爲 –

+0

,但全部在一行中,沒有表格。 – user2800989

+0

還有一個關閉在第8行丟失。有時表格可能會錯誤,當標籤不匹配 –

回答

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

謝謝大家。我添加了缺失的回聲,缺少,並從底部的第三行刪除了額外的。 仍然沒有格式化。結果在一條線上。 – user2800989

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>' 
?> 
+0

感謝大家。我添加了缺失的回聲,缺少,並從底部的第三行刪除了額外的。仍然沒有格式化。結果在一條線上。 – user2800989

+0

@ user2800989我編輯了代碼,請嘗試複製並粘貼此代碼。 –

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> 

希望這有助於

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>"; 
?>