help with loop generated tables from parsed ini file

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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==0 && $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($title, 0, 1) == $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']);
          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 } ?>

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.

Post Reply