Advertisement
Guest User

php functions

a guest
Feb 14th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2. include('../../Configuration.php');
  3.  
  4. $conn = mysqli_connect($host, $dbuser, $dbpass, $chardb);
  5. if (!$conn) {
  6.     die("Connection failed: " . mysqli_connect_error());
  7. }
  8.  
  9. $sql = "SELECT guid, name FROM characters";
  10. $result = mysqli_query($conn, $sql);
  11.  
  12. if (mysqli_num_rows($result) > 0) {
  13.     while($row = mysqli_fetch_assoc($result)) {
  14.         if(isset($_POST['guid'])) {
  15.             echo json_encode(
  16.                 array(
  17.                     array('id' => $row['guid'], 'name' => $row['name']),
  18.                     array('id' => $row['guid'], 'name' => $row['name']),
  19.                     array('id' => $row['guid'], 'name' => $row['name']),
  20.                 )
  21.             );
  22.         }
  23.     }
  24. } else {
  25.     echo "...";
  26. }
  27.  
  28. header('Content-Type: application/json');
  29. mysqli_close($conn);
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement