0

Why if I try to generate a table in a custom html it doesn't show a table?, it appears everything in the same line and I don't know why. This is the code:

{source}
<?php
  $db =& JFactory::getDBO();
  $query = $db->getQuery(true);
  $query->select($db->quoteName(array('a.Nombre','a.Email','a.Pais','a.Google','a.Skype','a.Password')))
        ->from($db->quoteName('#__chronoengine_chronoforms_datatable_Intercambios','a'));

  $db->setQuery($query);
  $options = $db->loadAssocList();~
?>

<p>
 <?php foreach( $options as $option ) { 
    $this_user_email = $option['Email']; 
    $this_user_skype = $option['Skype']; 
    this_user_name = $option['Nombre']; 
    $this_user_pais = $option['Pais'];
    $this_user_google = $option['Google'];
?>
</p>
<table border="1">
    <thead>
        <tr>
            <th>Nombre</th>
            <th>Nivel</th>
            <th>Pais</th>
            <th>Votos</th>
            <th>Skype</th> 
            <th>Hangout</th>
            <th>FaceTime</th>
            <th>Correo</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td> <?php print_r($this_user_name);?></td>
            <td> </td>
            <td><?php print_r($this_user_pais);?> </td>
            <td> </td>
            <td> <?php print_r($this_user_skype);?></td>
            <td> <?php print_r($this_user_skype);?></td>
            <td> </td>
            <td> <?php print_r($this_user_email);?></td>
        </tr>
    </tbody>
  </table>
  <?php } ?>
{/source}
1
  • How resulting HTML code looks like? Are all the table tags there?
    – miroxlav
    Commented Jan 28, 2015 at 0:30

3 Answers 3

2

The problem being is that you are echoing a full table foreach result. Have a look at this updated code and let me know what the outcome is:

{source}
<?php
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);

    $query->select($db->quoteName(array('a.Nombre','a.Email','a.Pais','a.Google','a.Skype','a.Password')))
          ->from($db->quoteName('#__chronoengine_chronoforms_datatable_Intercambios','a'));

    $db->setQuery($query);
    $options = $db->loadAssocList();
?>

<table border="1">
    <thead>
        <tr>
            <th>Nombre</th>
            <th>Nivel</th>
            <th>Pais</th>
            <th>Votos</th>
            <th>Skype</th> 
            <th>Hangout</th>
            <th>FaceTime</th>
            <th>Correo</th>
        </tr>
    </thead>
    <tbody>
        <?php
            foreach( $options as $option ) 
            { 
        ?>
            <tr>
                <td><?php print_r($option['Nombre']); ?></td>
                <td>&nbsp;</td>
                <td><?php print_r($option['Pais']); ?> </td>
                <td>&nbsp;</td>
                <td><?php print_r($option['Skype']); ?></td>
                <td><?php print_r($option['Google']); ?></td>
                <td>&nbsp;</td>
                <td><?php print_r($option['Email']); ?></td>
            </tr>
        <?php 
            } 
        ?>
    </tbody>
  </table>
{/source}

There was also a missing $ for one of your variables and a random ~ after the $options variable. I've also added &nbsp; for the blank table columns

1
  • Thanks, updated the answer
    – Lodder
    Commented May 27, 2019 at 16:08
0

Sourcerer is oriented to add simple PHP snippets.

Even if it is possible, I would not recommend to anyone to develop a module inside a custom html module.

BTW: please, do not tell me you want to show this module inside an article. :-D

0

if you use no editor, sourcerer strips all html tags. Use {source 0} .... {/source} to prevent it. sourcerer tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.