Jump to content

[SOLVED] PHP Table Expansion Code Problem


Zhadus

Recommended Posts

I am trying to basically make a table be able to expand and then contract semi-dynamically. The code I have currently will open a page with a table cell and a plus sign, when you push the plus sign it will reload the page with additional rows in the table. I would like for it to contract back once you click on the minus sign. It changes the variables ok and reloads the page but the added cells stay. Is there something I'm missing?

 

<?php

if (isset($_GET['expand'])) {
$expand = $_GET['expand'];
if ($expand == true) {
   $link = "<a href=expand.php?expand=false>-</a>";
   $name = "Close Me!";
} else {
  $link = "<a href=expand.php?expand=true>+</a>";
  $name = "Expand Me!";
}
} else {
  $expand = false;
  $link = "<a href=expand.php?expand=true>+</a>";
  $name = "Expand Me!";
}

echo "<center><table border=1 bordercolor=#000000 cellspacing=0 cellpadding=0 width=500 align=center>
<tr height=35 bgcolor=#c3c3c3><td width=470>$name</td><td width=30 align=center><b>[$link]</b></td></tr>";
if ($expand == true) {
echo "
<tr><td colspan=2>Expanded: $expand</td></tr>
<tr><td colspan=2>VALUE 1</td></tr>
<tr><td colspan=2>VALUE 2</td></tr>
<tr><td colspan=2>VALUE 3</td></tr>";
}
echo "</table></center>";
?>

Link to comment
https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/
Share on other sites

why not j ust do it in javascript so you don't have 50 reloads to expand/contract?

 

 

also this is a better idea

<?php
session_start();
if(isset($_GET['resize'])){
   if($_GET['resize'] == 1){
       $_SESSION['size'] = $_SESSION['size']+1;
    }
    elseif($_GET['reisze'] == 0){
        $_SESSSION['size'] = $_SESSSION['size']-1;
    }
}
if($_SESSION['size'] < 1){$_SESSION['size'] = 1;}
echo "<center><table border=1 bordercolor=#000000 cellspacing=0 cellpadding=0 width=500 align=center>
<tr height=35 bgcolor=#c3c3c3><td width=470>$name</td><td width=30 align=center><b>[$link]</b></td></tr>";
$i = 0;
while($i < $_SESSION['size']){
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
$i++;
}
echo "</table>";

echo "<a href=\"".$_SERVER['PHP_SELF']."?expand=1\">Expand</a>";
echo "<br />";

echo "<a href=\"".$_SERVER['PHP_SELF']."?expand=0\"Shrink</a>";

That would work but I have my reasons currently for only using PHP and HTML. I'd really like to keep it solely in PHP and I know that javascript would work better. With that said, is there any reason that my code doesn't work, regardless of optimization?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.