Ndeapo Silvanus
Ndeapo Silvanus

Reputation: 57

php table : How to Embed Buttons To cell Values In php table row

I want to Embed buttons with cell values to The following rows [COL 3],[COL 4],[COL 5]

but my code gets underlined red, I want to know what I am doing wrong

here is my code:


            echo 
            
            '<tr><td>'. $row["COL 2"] . 
            
            '<td><input type='button' class='buttons' value ='. $row["COL 3"] .
            '<td><input type='button' class='buttons' value ='. $row["COL 3"] .
            '<td><input type='button' class='buttons' value ='. $row["COL 3"] .


            '<td>'. $row["COL 6"] .
            
            '</td></tr>', 
            






Upvotes: 1

Views: 31

Answers (1)

&#201;der Rocha
&#201;der Rocha

Reputation: 1568

You have to escape the ' by using \ before them, as you see below:

echo 
            
    '<tr><td>'. $row["COL 2"] . 
    '<td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' />
    ...

or you could change the html ' by " as this sample:

           echo 
            
            '<tr><td>'. $row["COL 2"] . 
            
            '<td><input type="button" class="buttons" value ="'. $row["COL 3"] .
            '" />'
     ...

As solicited by Ndeapos Silvanus, and based on his code, here is the 'whole' example:

echo             
    '<tr>
        <td>'. $row["COL 2"] .'</td> 
        <td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' /></td>
        <td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' /></td>
        <td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' /></td>
        <td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' /></td>
        <td><input type=\'button\' class=\'buttons\' value =\''. $row["COL 3"] .'\' /></td>
    </tr>';

or with double quotes

echo             
    '<tr>
        <td>'. $row["COL 2"] .'</td> 
        <td><input type="button" class="buttons" value ="'. $row["COL 3"] .'" /></td>
        <td><input type="button" class="buttons" value ="'. $row["COL 3"] .'" /></td>
        <td><input type="button" class="buttons" value ="'. $row["COL 3"] .'" /></td>
        <td><input type="button" class="buttons" value ="'. $row["COL 3"] .'" /></td>
        <td><input type="button" class="buttons" value ="'. $row["COL 3"] .'" /></td>
    </tr>';

Upvotes: 1

Related Questions