Raahul Raahul - 5 months ago 19
PHP Question

Pass value with href in php inside echo

I need to pass value with href inside fetch array echo...

php code

$user = $get['username'];
$resource=mysqli_query($con,$sql);
echo "<font color=\"#000000\">
<h2 align=\"center\"></h2>

<table align=\"center\" border=\"1\" width=\"50%\">
<tr>
<td><b>GROUP NAME</b></td> <td><b>TASK TITLE 1</b></td> <td><b>TASK TITLE 2</b></td> <td><b>CREATED BY</b></td> <td><b>ASSIGNED TO</b></td> <td><b>DUE DATE</b></td> <td><b>PRIORITY</b></td> <td><b>CHANGE</b></td></tr> ";
while($result=mysqli_fetch_array($resource))
{
echo "<tr><td>".$result[0]."</td> <td>".$result[1]."</td> <td>".$result[2]."</td> <td>".$result[3]."</td> <td>".$result[4]."</td> <td>".$result[5]."</td> <td>".$result[6]."</td> <td> "<a href="changetask1.php?username='.$user.'">"</td></tr>";
} echo "</table></font>";


I need to pass username to next page with href value.

Answer

You are all messed up with quotes...

First... Learn to indent your code to make it readable.
Then, avoid echoing simple HTML if not necessary:

See your code after my Ā«formattingĀ»:
Try it, i've done a couple corrections...

<?php
$user=$get['username']; 
$resource=mysqli_query($con,$sql);
?>

<!-- This is only HTML -->
<font color="#000000">
    <h2 align="center"></h2>
    <table align="center" border="1" width="50%">
        <tr>
            <td><b>GROUP NAME</b></td>
            <td><b>TASK TITLE 1</b></td>
            <td><b>TASK TITLE 2</b></td>
            <td><b>CREATED BY</b></td>
            <td><b>ASSIGNED TO</b></td>
            <td><b>DUE DATE</b></td>
            <td><b>PRIORITY</b></td>
            <td><b>CHANGE</b></td>
        </tr>

        <?php
        // This is a PHP block until the next ?>

        while($result=mysqli_fetch_array($resource)){
            echo "<tr>
                    <td>".$result[0]."</td>
                    <td>".$result[1]."</td>
                    <td>".$result[2]."</td>
                    <td>".$result[3]."</td>
                    <td>".$result[4]."</td>
                    <td>".$result[5]."</td>
                    <td>".$result[6]."</td>
                    <td><a href='changetask1.php?username=".$user."'></td>
                  </tr>";
        }
        ?>

    </table>
</font>
Comments