I am using php database connectivity with "$row" as an array that stores name as a field in it .But after lots of searching i dint get how to pass php variable in angular js here's the code ,I am trying to achieve.how is it possible i am new to this your help will be appreciated.
<?php
$con = mysqli_connect('localhost','root','','practice');
if (!$con) {
die("couldnt connect". mysqli_error);
}
$q= "select * from test";
$result= $con->query($q);
if ($result->num_rows>0) {
while ($row = $result->fetch_assoc()) {
echo $row['name']."<br>";
}
}
print_r($result);
echo json_encode($result);
?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js">
</head>
<body>
<ul ng-init="names = <?php echo htmlspecialchars(json_encode($row)); ?>">
<li ng-repeat="x in names">
<p>{{x.name}}</p>
</li>
</ul>
</body>
</html>
echo $row['name']."<br>";
? when you check the page source will you see any data from the db? change that line toprint_r($row['name']);
and let me know if the data is fetched and printed (on your html page source) then we will get into solving the problem :) – Ali Jul 5 '15 at 8:54<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js">
– Ali Jul 5 '15 at 9:07<?php echo htmlspecialchars(json_encode($row)); ?>
? – Ali Jul 5 '15 at 10:09