help with loop generated tables from parsed ini file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Fri Apr 25, 2014 5:14 am

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">
$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 "";

else {echo "none";}
?> ;">
<table><tr height="30px"><td width="30px">
      <a href="<?php if ($app["Available"] == 0) {echo ""; 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>

<?php } ?>


the ini file is something like this:

Code: Select all

Args="/package "%cd%\software.msi" /somestrings
INSTALLDIR="C:\Program Files\Intuit\Reckon Accounts Premier 2014" MEDIAPACKAGEPATH="\" REBOOT="ReallySuppress" /quiet"

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

Last edited by leroyaus on Sun Apr 27, 2014 12:28 am, edited 1 time in total.

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

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">
<div style="margin:auto"><table>

foreach ($apps as $title => $app) {
$count 0;       
    if (
$count%4==&& $count<24) { echo "</tr><tr>"; }
    if (
$count==24) { 
        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 ""; echo $title; echo "%20on%20"; echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
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>

    <?php ?>


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.

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 10 guests