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 id="' id '"> <td></td><div > <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
I'm pretty sure the dollar sign is needed though and I don't know what I can do now.
CodePudding user response:
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>';
CodePudding user response:
Include jQuery script in your html.
Insert this line inseide in your html file
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
