Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

help with loop generated tables from parsed ini file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

help with loop generated tables from parsed ini file

Postby leroyaus » Fri Apr 25, 2014 5:44 am

hi all. this technically works, but is pretty buggy and I think I must be able to do this better.
The aim is to create an interface for a software deployment platform with about 200 applications.

I have a page where I parse an ini file and then run a for each loop which creates a table. It does this for each letter in the alphabet so for each letter it performs a new loop so effectively it loops through 26x200 sets of keys... as a result this is buggy.

the code:

Code: Select all
<div style="margin-left:auto;margin-right:auto;"><table>
<tr height="30px">
<?php
$count = 0;

foreach ($apps as $title => $app) {
   

   if ($count==4) { echo "</tr><tr height='30px'>"; }
      if ($count==8) { echo "</tr><tr height='30px'>"; }
            if ($count==12) { echo "</tr><tr height='30px'>"; }
                  if ($count==16) { echo "</tr><tr height='30px'>"; }
                     if ($count==20) { echo "</tr><tr height='30px'>"; }
                        if ($count==24) { $divcount++; echo "</tr></table></div><div class='down_up' align='center'>
                        <a href='#divcount"; echo $divcount; echo "' >&#9660;</a></div></div><div class='box' id='divcount";
                        echo $divcount;
                        echo"'><div style='margin-left:auto;margin-right:auto;'><br><br><table><tr height='30px'>"; $count = 0;}

   ?>

   
      <td width="252px" style="display:<?php
if(substr($title, 0, 1) == $letter) {
echo "";
$count++;
}

else {echo "none";}
?> ;">
<table><tr height="30px"><td width="30px">
      <a href="<?php if ($app["Available"] == 0) {echo "mailto:helpdesk@company.com.au?Subject=Please%20Install%20"; echo $title; echo "%20on%20"; echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
      echo "&body=Automatically%20generated%20email%20request%20from%20the%20Self%20Service%20Software%20Portal%20for%20computer%20name:%20";
      echo gethostbyaddr($_SERVER['REMOTE_ADDR']);} else {echo "RSMLaunch://"; echo $title;} ?>" class="icon">
      <img src="./<?php if ($app["Available"] == 0) {echo $app["Image"]; echo ".un.png";} else {echo $app["Image"];} ?>"></a>
</td><td width="222px">
      <div class="texter"><?php echo $title; ?></div>
   </td></tr></table>
   </td>

<?php } ?>
</tr>
</table>
<br>
<br>

</div>


the ini file is something like this:

Code: Select all
[Software]
Image=iconforsoftware.png
Guid={E019B3D4-1963-43D6-98D7-DBF4B64EDC57}
Command=msiexec.exe
Args="/package "%cd%\software.msi" /somestrings
INSTALLDIR="C:\Program Files\Intuit\Reckon Accounts Premier 2014" MEDIAPACKAGEPATH="\" REBOOT="ReallySuppress" /quiet"
RunOnce=messagebox.exe
DateAdded=17-10-1900
InstallCount=0
Family=software_family
Popular=no
Available=true
Location=all


Any help on how to do this better would be appreciated. fyi, the deployment part works 100%, purely an interface question.

Thanks!
Last edited by leroyaus on Sun Apr 27, 2014 12:28 am, edited 1 time in total.
leroyaus
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Apr 25, 2014 5:14 am

Re: help with loop generated tables from parsed ini file

Postby seandisanti » Fri Apr 25, 2014 6:07 pm

You're overcomplicating things by using inline styling, unnecessary conditions, and not using concatenation. Here's a quick little rewrite eliminating a couple of things....
Code: Select all

<style type="text\css">
tr{
height=30px;
}
.down_up{
align:center;
}
    
<div style="margin:auto"><table>
    <tr>
    <?php


    
foreach ($apps as $title => $app) {
    
$count 0;       
    if (
$count%4==&& $count<24) { echo "</tr><tr>"; }
    if (
$count==24) { 
        
$divcount++; 
        echo </
tr></table></div><div class='down_up'><a href='#divcount" . $divcount . ' >&#9660;</a></div></div><div class='box' id='divcount" . $divcount'><div style='margin:auto;'><br /><br /><table><tr>"; 
}
       
?>

       
          <td width="252px" style="display:<?php echo (substr($title01) == $letter)?"":"none";?>
    <table><tr height="30px"><td width="30px">
          <a href="<?php if ($app["Available"] == 0) {echo "mailto:helpdesk@rsmi.com.au?Subject=Please%20Install%20"; echo $title; echo "%20on%20"; echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
          echo 
"&body=Automatically%20generated%20email%20request%20from%20the%20Self%20Service%20Software%20Portal%20for%20computer%20name:%20";
          echo 
gethostbyaddr($_SERVER['REMOTE_ADDR']);} else {echo "RSMLaunch://"; echo $title;} ?>" class="icon">
          <img src="./<?php if ($app["Available"] == 0) {echo $app["Image"]; echo ".un.png";} else {echo $app["Image"];} ?>"></a>
    </td><td width="222px">
          <div class="texter"><?php echo $title?></div>
       </td></tr></table>
       </td>

    <?php ?>
    </tr>
    </table>
    <br>
    <br>

    </div>

you should also when possible try to avoid going in and out of php blocks. It hurts readability and definitely over complicates code, and can make it very difficult especially in files where you also use javascript or jquery.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron