Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Append Table row to existing Table PHP, Javascript

I’m trying to make a Table where the user is able to see some data from a database.

To do this im using this js code to append a row for every entity:

     function append(id, name){
    $table_body = $('#tbody');
    //html of the table row
    $table_row = $('<tr class="edit" id="' + id + '"> <td></td><div class="checkbox"> <label><input type="checkbox" name="checkbutton">checkbox</label></div><td>' + name + '</td></tr>');
    //append row
    $table_body.append($table_row);
    $('#avatartable').show();
  }

with that code I’m gettin this error: Uncaught ReferenceError: $ is not defined

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m pretty sure the dollar sign is needed though and I don’t know what I can do now.

>Solution :

As far as I know, you can NOT combine PHP and JavaScript at the same time in a function (execept to write the js code with echo or something similar)!
-Php is a back-end language (executed in server)
-JS is a front-end language (executed in browser)

if all you want is to display data from database into a HTML table just put a php script inside the tbody, loop through your array an echo the rows
something like

foreach($array as $value)
    echo '<tr><td>'.$value.'</td><td>...</td></tr>';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading