Spectre Posted August 3, 2009 Share Posted August 3, 2009 I'm trying to pass table cell ID's as a var $cell for example, so I can do $move = $cell; and i've got code in place for $move to echo a certain link. My table is as follows right now (beware it's a mess right now) $img = '<img src=images/cs/grassthumb.jpg style="opacity:1;filter:alpha(opacity=100)" onmouseover="this.style.opacity=0.6;this.filters.alpha.opacity=60" onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100" />'; if($move == "TL"){ $linky = 'wland.php?action=upleft'; } if($move == "TR"){ $linky = 'wland.php?action=upright'; } if($move == "BL"){ $linky = 'wland.php?action=downleft'; } if($move == "BR"){ $linky = 'wland.php?action=downright'; } if($move == "TM"){ $linky = 'wland.php?action=up'; } if($move == "BM"){ $linky = 'wland.php?action=down'; } if($move == "MR"){ $linky = 'wland.php?action=right'; } if($move == "MM"){ $linky = 'wland.php'; } if($move == "ML"){ $linky = 'wland.php?action=down'; } $onclick = 'onclick="window.location.href=\''.$linky.'\'"'; $link = $onclick; ?> <table align="center" cellpadding="0" cellspacing="0" id="navTab"> <tr> <td id="TL" <? echo $link;?>><? echo $img; ?></td><td id="TM" <? echo $link;?>><? echo $img; ?></td><td id="TR" <? echo $link;?>><? echo $img; ?></td> </tr> <tr> <td id="ML" <? echo $link;?>><? echo $img; ?></td><td id="MM" <? echo $link;?>><? echo $img; ?></td><td id="MR" <? echo $link;?>><? echo $img; ?></td> </tr> <tr> <td id="BL" <? echo $link;?>><? echo $img; ?></td><td id="BM" <? echo $link;?>><? echo $img; ?></td><td id="BR" <? echo $link;?>><? echo $img; ?></td> </tr> </table> <? Some help getting this working would be VERY helpful. Idea is to have a little 3x3 grid used to explore an area. I'm probably going about it all wrong though. Quote Link to comment https://forums.phpfreaks.com/topic/168706-solved-table-help/ Share on other sites More sharing options...
mikesta707 Posted August 3, 2009 Share Posted August 3, 2009 yeah your going about this in a somewhat screwy way. The way I would do what your trying to do is build the table with php echo commands, and put all the different td id's into an array, and iterate through that array. something along the lines of $ids = array("tl", "ml", "bl"); foreach($ids as $move){ if($move == "TL"){ $linky = 'wland.php?action=upleft'; } if($move == "TR"){ $linky = 'wland.php?action=upright'; } if($move == "BL"){ $linky = 'wland.php?action=downleft'; } if($move == "BR"){ $linky = 'wland.php?action=downright'; } if($move == "TM"){ $linky = 'wland.php?action=up'; } if($move == "BM"){ $linky = 'wland.php?action=down'; } if($move == "MR"){ $linky = 'wland.php?action=right'; } if($move == "MM"){ $linky = 'wland.php'; } if($move == "ML"){ $linky = 'wland.php?action=down'; } $onclick = 'onclick="window.location.href=\''.$linky.'\'"'; $link = $onclick; echo "<td id=\"$move\" $link >"; //the other stuff } I dont know why you have the $link variable. You can just use the $onclick variable. hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/168706-solved-table-help/#findComment-890057 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 I'm not sure what exactly you are trying to do (can't figure it out. brain is mush....), but I did notice that you could use a switch better: <?php $img = '<img src=images/cs/grassthumb.jpg style="opacity:1;filter:alpha(opacity=100)" onmouseover="this.style.opacity=0.6;this.filters.alpha.opacity=60" onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100" />'; $linky = "wland.php?action="; switch ($move){ case "TL": $linky .= 'upleft'; break; case "TR": $linky .= 'upright'; break; case "BL": $linky .= 'downleft'; break; case "BR": $linky .= 'downright'; break; case "TM": $linky .= 'up'; break; case "BM": $linky .= 'down'; break; case "MR": $linky .= 'right'; break; case "MM": $linky = 'wland.php'; break; case "ML": $linky .= 'down'; break; } $onclick = 'onclick="window.location.href=\''.$linky.'\'"'; $link = $onclick; ?> <table align="center" cellpadding="0" cellspacing="0" id="navTab"> <tr> <td id="TL" <? echo $link;?>><? echo $img; ?></td><td id="TM" <? echo $link;?>><? echo $img; ?></td><td id="TR" <? echo $link;?>><? echo $img; ?></td> </tr> <tr> <td id="ML" <? echo $link;?>><? echo $img; ?></td><td id="MM" <? echo $link;?>><? echo $img; ?></td><td id="MR" <? echo $link;?>><? echo $img; ?></td> </tr> <tr> <td id="BL" <? echo $link;?>><? echo $img; ?></td><td id="BM" <? echo $link;?>><? echo $img; ?></td><td id="BR" <? echo $link;?>><? echo $img; ?></td> </tr> </table> <? Quote Link to comment https://forums.phpfreaks.com/topic/168706-solved-table-help/#findComment-890059 Share on other sites More sharing options...
Spectre Posted August 3, 2009 Author Share Posted August 3, 2009 Thanks mike! With a little modding (count adding to echo out the cells in the right format) it works good Now if I can work the other bits I have in mind, I'll be set and can forget about this little pet project knowing it's done lol. Quote Link to comment https://forums.phpfreaks.com/topic/168706-solved-table-help/#findComment-890103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.