0

我创建了 2 个 chronoforms,一个是登录用户创建其客户的记录,第二个是向同一登录用户显示这些客户列表及其详细信息的表单。

这是我放在自定义代码 Chronoforms 元素中的代码:

    <?php 
    defined('_JEXEC') or die();
    $user =& JFactory::getUser();
    $usr_id = $user->get('id');
    $usr_name = $user->get('name');
    echo $usr_id;
    $db = &JFactory::getDBO();
    $query = "SELECT * FROM crd_chronoforms_data_RepsClient WHERE cf_created_by = '$usr_id'";
    $db->setQuery($query);
    $data = $db->loadObjectList();
foreach($form->data['crdchronoformsdataRepsClient'] as $detail);

    ?>
    <table>
    <tr>
<th>Client</th>
<th>Contact Name</th>
<th>Contact Number</th>
<th>&nbsp;</th>
</tr>
<tr>
<td><?php echo  $detail['cf_rep_client'];?></td>
<td><?php echo  $detail['cf_rep_contact'];?></td>
<td><?php echo  $detail['cf_rep_tel'];?></td>
<td><a href="index.php?option=com_chronoforms&chronoform=reps_clients&token=<?php echo $detail['cf_uid'];?>">Edit</td>
    </tr>
    </table>

但是,目前,所有列表显示的是登录用户 ID# 即

回声 $usr_id;

我不知道我的语法在哪里被炸毁了。感谢任何帮助和新鲜的眼睛。


现在出现新错误...

致命错误:不能在 /home/cardosoc/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(19) 中使用 stdClass 类型的对象作为数组:第 26 行的 eval() 代码

       <?php
   $user = JFactory::getUser();
   $usr_id = $user->id;
   $usr_name = $user->username;
   echo $usr_name;

   $db = JFactory::getDBO();
   $query = $db->getQuery(true);   
   $query->select('*')
    ->from('#__chronoforms_data_RepsClient')
    ->where('cf_created_by ='. $usr_id);   
   $db->setQuery($query);
   $data = $db->loadObjectList();

   foreach($data as $detail): 
   ?>
   <table>
       <tr>
    <th>Client</th>
    <th>Contact Name</th>
    <th>Contact Number</th>
    <th>Address</th>
    <th>&nbsp;</th>    
   </tr>
       <tr>
    <td><?php echo $detail['rep_client'];?></td>
    <td><?php echo $detail['rep_contact'];?></td>
    <td><?php echo $detail['rep_tel'];?></td>
    <td><?php echo $detail['rep_client_address'];?></td>
    <td><a href="index.php?option=com_chronoforms&chronoform=reps_clients&token=<?php echo $detail['cf_uid'];?>">Edit</td>
   <?php endforeach; ?>
       </tr>
   </table>

但是......如果我改变

foreach($data as $detail): TO foreach($db as $detail):

我得到回应

m m m m 
4

1 回答 1

1

尝试使用它使用 Joomla 2.5 编码标准 + 一些更改:

$user = JFactory::getUser();
$usr_id = $user->id;
$usr_name = $user->username;
echo $usr_id;

$db = JFactory::getDBO();
$query = $db->getQuery(true);   
$query->select('*')
      ->from('#__crd_chronoforms_data_RepsClient')
      ->where('cf_created_by = ' . $usr_id);   
$db->setQuery($query);
$data = $db->loadObjectList();

foreach ($data as $detail) : ?>
<table>
    <tr>
        <th>Client</th>
        <th>Contact Name</th>
        <th>Contact Number</th>
        <th>&nbsp;</th>
    </tr>
    <tr>
        <td><?php echo $detail['cf_rep_client'];?></td>
        <td><?php echo $detail['cf_rep_contact'];?></td>
        <td><?php echo $detail['cf_rep_tel'];?></td>
        <td><a href="index.php?option=com_chronoforms&chronoform=reps_clients&token=<?php echo $detail['cf_uid'];?>">Edit</td>
    </tr>
</table>
<?php endforeach; ?>

您也没有正确定义数据库表。让我知道这个是否奏效。

于 2013-05-30T15:12:56.110 回答