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
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
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
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.