Jump to content

[SOLVED] Table help


Spectre

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/168706-solved-table-help/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/168706-solved-table-help/#findComment-890057
Share on other sites

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>
<?

Link to comment
https://forums.phpfreaks.com/topic/168706-solved-table-help/#findComment-890059
Share on other sites

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.