简体   繁体   中英

tr link with php code inside

I'm trying to do something a little weird and I'm kind of lost.

I have this code:

<tr onclick="href='<?php if (isset($_SESSION['id_usuario'])){ echo 'logado.php?'; } else { echo 'index.php?'; } ?>grupo=<?php echo $row_buscainterna['id_grupo']; ?>'">

My <tr> are in hover, so when the user clicks it I would like to perform this "php action" Can't make it work. Can somebody help me?

What do you think about it?

我认为将链接放在tr标记内并设置其样式以使其达到tr的大小会更容易。

You would like to use code like this:

<tr onclick="window.location.href='<?php if (isset($_SESSION['id_usuario'])){ echo 'logado.php?'; } else { echo 'index.php?'; } ?>grupo=<?php echo $row_buscainterna['id_grupo']; ?>'">

Here is an example

OnClick attribute should contain javascript code. Your example sets global variable href to some URL.

If you want to send the user to this URL, then you shoud use document.location instead of href :

<tr onclick="document.location='<?php if (isset($_SESSION['id_usuario'])){ echo 'logado.php?'; } else { echo 'index.php?'; } ?>grupo=<?php echo $row_buscainterna['id_grupo']; ?>'">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM