Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can utilize the <code>ng-repeat</code> function to iterate through each row of your query results. In this example I used a <code>&lt;table&gt;</code> structure and placed an <code>ng-repeat</code> function inside a <code>&lt;tr&gt;</code> element, but you can use <code>ng-repeat</code> on other element types, like <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code>, if you prefer. </p> <pre><code>&lt;body id="ng-app" ng-app="sotest"&gt; &lt;div ng-controller="searchCtrl"&gt; &lt;form class="well form-search"&gt; &lt;label&gt;Search:&lt;/label&gt; &lt;input type="text" ng-model="keywords" class="input-medium search-query" placeholder="Keywords..."&gt; &lt;button type="submit" class="btn" ng-click="search()"&gt;Search&lt;/button&gt; &lt;p class="help-block"&gt;Single words only: eg; AFS, University, Geology&lt;/p&gt; &lt;/form&gt; &lt;table&gt; &lt;tr&gt; &lt;!-- this is the column header row --&gt; &lt;th&gt;AwardName&lt;/th&gt; &lt;th&gt;SomeColumnName&lt;/th&gt; &lt;/tr&gt; &lt;tr ng-repeat="row in result"&gt; &lt;!-- this tr will generate for each row in the query result--&gt; &lt;td&gt;{{row.AwardName}}&lt;/td&gt; &lt;td&gt;{{row.SomeColumnName}}&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Additionally, I suggest using the angularJS DeferredAPI and Promises to get your async data. You will need to inject $q into your controller to do so. Note I have restructured your JS code slightly, separating the database call into a function. </p> <pre><code>&lt;script type="text/javascript" src="http://code.angularjs.org/1.0.8/angular.min.js"&gt;&lt;/script&gt; &lt;script type="Text/javascript" &gt; var app = angular.module('sotest', []); app.controller('searchCtrl',['$scope','$http','$q', function SearchCtrl($scope, $http, $q) { $scope.search = function(){ $scope.result = $scope.fetchData(); } $scope.fetchData= function() { $scope.url = 'index.php'; var deferred = $q.defer(); $http.post($scope.url). success(function(data, status) { deferred.resolve(data) }) . error(function(data, status) { deferred.reject('An unexpected error has occurred'); }); return deferred.promise; //return the data }; }]); &lt;/script&gt; </code></pre> <p>I modified your PHP to return a JSON-encoded array, and added the $db connection to your mysql_query line:</p> <pre><code>$data = file_get_contents("php://input"); $objData = json_decode($data); $db = mysql_connect("xxxxxxxx", "xxxxxxxx", "xxxxxxxx") or die ("Error connecting to database."); mysql_select_db("Awards_New", $db) or die ("Couldn't select the database."); $results = mysql_query('SELECT * FROM Awards WHERE AwardName LIKE "%'. $objData-&gt;data .'%"', $db); $array_result = array(); while($row = mysql_fetch_array($result)){ $array_result[] = $row; } echo json_encode($array_result); mysql_close($db); </code></pre> <p>You can read more on $q and deferred promises here: http://docs.angularjs.org/api/ng.$q</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload