Jump to content

mysql, smarty foreach loop in new client page


mearls

Recommended Posts

I am in the process of building a new client facing page but have run into an odd issue. I have created a new table in mysql, created a new page in whmcs and in the templates. In the tpl file I use a foreach loop and it seems to always loop 20 times, even though the database entry has 1 entry in it.

 

Any thoughts or suggestions would be great.

 

 

<?php

define("CLIENTAREA",true);
define("FORCESSL",true); # Uncomment to force the page to use https://

require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");

$pagetitle = $_LANG['clientareatitle'];
$breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
$breadcrumbnav .= ' > <a href="mypage.php">My Page</a>'; 

initialiseClientArea($pagetitle,'',$breadcrumbnav);

# To assign variables to the template system use the following syntax.
# These can then be referenced using {$variablename} in the template.

$smartyvalues["variablename"] = $value; 

# Check login status
if ($_SESSION['uid']) {

 # User is logged in - put any code you like here

 # Here's an example to get the currently logged in clients first name

 $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
 $data = mysql_fetch_array($result);
 $clientname = $data[0];
 $smartyvalues["clientname"] = $clientname;

} else {

 # User is not logged in

}

[color="#B22222"]$results = mysql_query("SELECT `tblserversStatus` . * FROM tblhosting, tblserversStatus WHERE tblhosting.server = tblserversStatus.id and tblhosting.userid=".(int)$_SESSION['uid']);

 while ($mytype = mysql_fetch_array($results)) 
{
       $smartyvalues[mytype] = $mytype;
}[/color]

# Define the template filename to be used without the .tpl extension

$templatefile = "serverhealth"; 

outputClientArea($templatefile);

?>

 

{include file="$template/pageheader.tpl" title="Server Health" desc="Listed below is the real time status of the server(s) for your account"}
<p>These statuses come directly from our external monitoring system in real time.</p>

       <table class="zebra-striped">  
       <thead>
         <tr>
               <th>key</th>
               <th>id</th>
               <th>Server</th>
               <th>HTTP</th>
               <th>FTP</th>
               <th>MySQL</th>
               <th>POP</th>
               <th>IMAP</th>
               <th>SMTP</th>
               <th>SSH</th>
         </tr>
        </thead>
        <tbody>

{foreach item=status from=$type} 
         <tr>
               <td>{$type.id}</td>
               <td>{$type.name}</td>
               <td><span class="label {$type.http}">{$type.http}</span></td>
               <td><span class="label {$type.ftp}">{$type.ftp}</span></td>
               <td><span class="label {$type.mysql}">{$type.mysql}</span></td>
               <td><span class="label {$type.pop}">{$type.pop}</span></td>
               <td><span class="label {$type.imap}">{$type.imap}</span></td>
               <td><span class="label {$type.smtp}">{$type.smtp}</span></td>
               <td><span class="label {$type.ssh}">{$type.ssh}</span></td>
         </tr>
{/foreach}
       </tbody>
       </table>

 

Output on the page:

id Server HTTP FTP MySQL POP IMAP SMTP SSH

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

2 tra up down unconfirmed_down unknown paused up up

 

Export from mysql table:

Export Data from the table:

id name ipaddress http ftp mysql pop imap smtp ssh

20 tra 10.10.10.10 up down unconfirmed_down unknown paused up up

Link to comment
Share on other sites

I was able to print out the array before the foreach loop and I still do not understand why its adding so many more lines.

 

Array ( [0] => 26 [id] => 26 [1] => tra [name] => lanzarote [2] => 10.10.10.10 [ipaddress] => 10.10.10.10 [3] => up [http] => up [4] => down [ftp] => down [5] => unconfirmed_down [mysql] => unconfirmed_down [6] => unknown [pop] => unknown [7] => paused [imap] => paused [8] => up [smtp] => up [9] => up [ssh] => up ) 1

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated