So. I'm making a Forum, and I want to build it with using AngularJS.
First off.
Now, I've set up a connection to my database with:
<?php
session_start();
$db = new mysqli("localhost","root","","uf") or die ("ERROR! With connection!");
function sql($query){
return mysql_query($query);
}
$sql = "SELECT forum_id, forum_name, forum_desc, forum_created FROM forum_tbl";
if($query = $db->prepare($sql)){
$query->bind_result($f_id, $f_name, $f_desc, $f_created);
$query->execute();
$query->store_result();
}else{
echo $db->error;
}
?>
It's separated to 2 files, First being db_connect.php and second core.php
I've made the tables above, they have sample data.
How can I now make the f_id, f_name,.. to JSON encoded data? And use that JSON in my main.js file to use data.forumid?
I have made php to read the data from the database using:
<?php if($query->num_rows !==0):
while($row = $query->fetch()):
?>
<tr>
<td><?= $f_id;?></td>
<td><a href="#/HELPME"><?= $f_name;?></a></td>
<td><?= $f_desc;?></td>
<td><?= $f_created;?></td>
</tr>
<?php endwhile; endif; ?>
BUT I do NOT want to read the data like that. I would love to use ng-repeat.
So.
I did this with....
<a ng-click="setRoute('forum')" href="#/forum/id=<?php echo $f_id;?>" class="list-group-item">Link</a>
And in my html is ofcourse the ng-app="urheilu"
var app = angular.module('urheilu', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/forum/id=:id', {
templateUrl: function(urlattr){
return 'app/components/forums/threadlist.php?id=' + urlattr.id + '';
}
})
});
Thats how I did my dynamic linking.
DONE.
-Kevin