-2

I have the following script who list some sql values in a table

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))  {

            $idOfUrl = $row['2'];

            echo("<tr onclick='window.location.href = \"


// how can i insert here a  php value ? --> $idOfUrl

                \"';>");
            echo("<td>");
            echo $row['1'];
            echo("</td>");
            echo ("</tr>"); 
            echo("</a>");
            }

I want to make the entire row clickable to a page with an ID whos from the SQL table.

Thank you in advance !

6
  • 1
    you should learn about server side languages (php for example) and client side (javascript for example). To run php as you want you need to use ajax Commented May 8, 2018 at 8:34
  • You just paste it there where you want it: echo("<tr onclick='window.location.href = \"$idOfUrl\"';>"); Commented May 8, 2018 at 8:35
  • The same way you did with echo $row['1']; Commented May 8, 2018 at 8:36
  • 1
    @LelioFaieta tho you're right about learning the difference between server side and client side, here is not the case because he has the id in php and echos just the javascript. So he needs just to concatenate the id of the URL to the string. Commented May 8, 2018 at 8:37
  • @edwin the easy way doesn't mean it's the right way Commented May 8, 2018 at 8:38

2 Answers 2

0

you want to insert a PHP variable while you are in PHP. this is very simple:

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))  {

    $idOfUrl = $row['2'];

    echo("<tr onclick='window.location.href = ".$idOfUrl."';>");
    echo("<td>");
    echo $row['1'];
    echo("</td>");
    echo ("</tr>"); 
    echo("</a>");
}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you bro ! theses "." were missing !
0

try

echo("<tr onclick='window.location.href=".$idOfUrl."';>");

or

echo("<tr onclick='window.location.href=\"$idOfUrl\"';>");

maybe thats hope you

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.