Zhadus Posted April 10, 2008 Share Posted April 10, 2008 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 More sharing options...
Zhadus Posted April 10, 2008 Author Share Posted April 10, 2008 Anyone able to offer any help or have suggestions of some more information I can provide? I am using PHP 5. Link to comment https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/#findComment-514060 Share on other sites More sharing options...
cooldude832 Posted April 10, 2008 Share Posted April 10, 2008 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>"; Link to comment https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/#findComment-514097 Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Author Share Posted April 10, 2008 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? Link to comment https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/#findComment-514100 Share on other sites More sharing options...
cooldude832 Posted April 10, 2008 Share Posted April 10, 2008 your main problem is you are trying to use string values true and false to replace conditional values of TRUE and FALSE that is why I like 1/0 as it works in non bitwise comparisons as both a string and an integer. Link to comment https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/#findComment-514104 Share on other sites More sharing options...
Zhadus Posted April 10, 2008 Author Share Posted April 10, 2008 Perfect! Thank you so much. I see where my errors were and It's definitely as plain as day at the moment. Thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/100494-solved-php-table-expansion-code-problem/#findComment-514111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.