1

If I click the Preview button in my article, it displays the table exactly as I thought I had set-up. However, if I try to click through and get the page to display on the front-end, no table is shown. What is causing Joomla to not show the table?

<?php

    $param1 = $_GET['param1'];
    $param2 = $_GET['param2'];
    $param3 = $_GET['param3'];

    $server = "Server"; 
        $uid = "uid"; 
        $pwd = "pwd"; 
        $database = "DB"; 

    $conn = mssql_connect($server,$uid,$pwd);

    if ($conn===false)
    {
        echo '<p>Cannot connect to SQL Server Database. Please try again later.</p>';
        exit;
    }
    if (mssql_select_db($database,$conn) === false) 
    {
        echo '<p>Cannot connect to DB. Please try again later.</p>';
        exit;
    }
    $proc = mssql_init('ProcedureName',$conn);
    mssql_bind($proc,'@param1',$param1,SQLVARCHAR);
    mssql_bind($proc,'@param2',$param2,SQLVARCHAR);
    mssql_bind($proc,'@param3',$param3,SQLVARCHAR);
    if ($result = mssql_execute($proc)) 
    {
        $number_of_rows = mssql_num_rows($result);
        if($number_of_rows > 0) {
            echo '<table border="1">';
            echo '<tr>';
            echo '  <th>Employee </th>';
            echo '  <th>EmployeeID </th>';
            echo '  <th>Sale Price </th>';
            echo '  <th>Tax Price </th>';
            echo '  <th>Total Price </th>';
            echo '  <th>Market Price </th>';
            echo '</tr>';  

        while ($Row = mssql_fetch_assoc($result)) 
        {
            echo '<tr><td>'.$Row['Employee'] . 
            '</td><td>'.$Row['EmployeeID'] . 
            '</td><td>'."$".round($Row['SalePrice']) . 
            '</td><td>'."$".round($Row['TaxPrice']) . 
            '</td><td>'."$".round($Row['TotalPrice']) . 
            '</td><td>'."$".round($Row['MarketPrice']) . 
            '</td></tr>';
        }
            echo '</table>';
        }
        mssql_close($con);
    }
?>
4
  • ln 26, you have a typo.its mysql not mssql
    – saibbyweb
    Commented Feb 26, 2017 at 5:32
  • I am using mssql, not mysql. This syntax returns the results as needed, it just does not create the table. Commented Feb 26, 2017 at 16:43
  • Have you checked CSS in front-end? It's not unusal for table selector to be heavily modified by template.css.
    – Mikan
    Commented Feb 26, 2017 at 20:25
  • Are you writing php directly inside the article? Check here: joomla.stackexchange.com/questions/19193/adding-php-in-article
    – FFrewin
    Commented Feb 28, 2017 at 8:59

2 Answers 2

0

I can't see anything wrong with the echos, if the editor does not remove your code, i would suggest to remove one by one the following ifs to see if it is echoing the table headers no matter the query results

if ($result = mssql_execute($proc)) {
if($number_of_rows > 0) {

Also make sure you get at least one result from the query by changing all the table data code with something like this

while ($Row = mssql_fetch_assoc($result)) {
    echo $Row['Employee'];
}

UPDATE:

If you place your code strait in the article it wont work try using an extension like Regular Labs - Sourcerer and place your code inside the

{source} your code {/source}

then give it a try

3
  • 1
    I removed both if statements, but the table is still not being displayed. Interesting thing about it, I have the same syntax in an external php file that populates a div tag in the article and it creates the table perfectly. However, when running the syntax in the article itself it does not create the table. Commented Feb 26, 2017 at 23:47
  • 1
    @IcyPopTarts the table is not showing but if you inspect the source code using your Browser Inspector, is the code for the table there?
    – Lodder
    Commented Feb 27, 2017 at 10:54
  • @Lodder - if I right click the page and say view source, the content is placed in a div tag and has no table structure. Commented Feb 27, 2017 at 15:20
0

You should not add php to the articles, also your code is very dangerous, you are using params without any escaping and filtering.

2
  • How should the code be setup? Commented Feb 28, 2017 at 15:19
  • You should use JInput docs.joomla.org/Retrieving_request_data_using_JInput and specify appropriate filters, right now you are open to varios hacking attack as you use no filtering for values you are getting from URL - you use them directly in the query
    – Klas
    Commented Jul 24, 2017 at 12:32

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.