use Ionic framework with php files -


i'm creating mobile app ionic framework. got html pages created online. want backend code data sql server. receiving data no problem php. when use php pages don't have interface created ionic.

how can use php pages (instead of html) , still lay out ionic? example: scorebord.php

<?php $servername = "localhost:3306"; $username = "ssss"; $password = "dffd"; $dbname = "ddddd";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  $sql = "select user_username,user_city,user_highscore tbl_user"; $result = $conn->query($sql); ?> <ion-view style="" title="scorebord">     <ion-content class="has-header" overflow-scroll="true" padding="true" style="background: url(img/hx1ml1tvggabo3ene6qg_menu3.png) no-repeat center;">         <h1 style="">scorebord</h1>         <table style="width:100%">             <?php             if ($result->num_rows > 0) {                 // output data of each row                 while ($row = $result->fetch_assoc()) {                     ?>                      <tr>                         <td><?php echo $row["user_username"] ?></td>                      </tr>                     <?php                 }             } else {                 echo "0 results";             }             $conn->close();             ?>          </table>      </ion-content> </ion-view> 

btw: safe configure database in php file that? alternative?

the mobile app saved on device can't interpret php code, unlike web server. if dont know/want javascipt iframe option.

example.com/table.php

        <h1 style="">scorebord</h1>         <table style="width:100%">             <?php             if ($result->num_rows > 0) {                 // output data of each row                 while ($row = $result->fetch_assoc()) {?>                     <tr> <td><?php echo $row["user_username"] ?></td></tr>                     <?php                 }             } else {                 echo "0 results";             }             $conn->close();             ?>         </table>  

your app

<ion-view style="" title="scorebord">     <ion-content class="has-header" overflow-scroll="true" padding="true" style="background: url(img/hx1ml1tvggabo3ene6qg_menu3.png) no-repeat center;">         <iframe src="example.com/table.php"/>     </ion-content> </ion-view> 

but better solution use javascript make http requests json data or full html templates(like table.php).

i use json backend

highscores.php

<?php $servername = "localhost:3306"; $username = "ssss"; $password = "dffd"; $dbname = "ddddd";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  $sql = "select user_username,user_city,user_highscore tbl_user"; $result = $conn->query($sql); $json = mysqli_fetch_all ($result, mysqli_assoc); echo json_encode($json); 

your app

angular.module('ionicapp', [])  .controller('mainctrl', function($scope, $http) {   $http.get('http://example.com/highscores.php').then(function(resp) {     $scope.users = resp.data;   }, function(err) {     console.error('err', err);   }) });    <html ng-app="ionicapp">   <body ng-controller="mainctrl">     <ion-content>       <ion-list>         <ion-item ng-repeat="user in users">           {{user.user_username}}         </ion-item>       </ion-list>     </ion-content>   </body> </html> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -