Advertisement
Guest User

json_encoder

a guest
May 12th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2.  $hostname = "127.0.0.1";
  3.  $username = "wordpress";
  4.  $password = "wordpress";
  5.  $db = "preventivi";
  6.  
  7.  $conn = mysqli_connect($hostname, $username, $password, $db) or die(mysqli_connect_error());
  8.  if (mysqli_connect_errno()) {
  9.    echo "Connessione fallita: " . die(mysqli_connect_error());
  10.  }
  11.  
  12.  $result = mysqli_query($conn, "SELECT * FROM categorie");
  13.  $rows = array();
  14.  
  15.  while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  16.    $rows[] = array(
  17.       'id' => $row['id'],
  18.       'nome' => $row['nome'],
  19.       );
  20.  }
  21.  
  22.  $result2 = mysqli_query($conn, "SELECT * FROM elementi");
  23.  $rows2 = array();
  24.  
  25.  while ($row = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
  26.    $rows2[] = array(
  27.       'id' => $row['id'],
  28.       'id_cat' => $row['id_cat'],
  29.       'nome' => $row['nome'],
  30.       );
  31.  }
  32.  
  33.  $result3 = mysqli_query($conn, "SELECT * FROM opzioni");
  34.  $rows3 = array();
  35.  
  36.  while ($row = mysqli_fetch_array($result3, MYSQLI_ASSOC)) {
  37.    $rows3[] = array(
  38.       'id' => $row['id'],
  39.       'id_elemento' => $row['id_elemento'],
  40.       'nome' => $row['nome'],
  41.       'prezzo' => $row['prezzo'],
  42.       );
  43.  }
  44.  
  45.  while ($row = mysqli_fetch_array($result3, MYSQLI_ASSOC)) {
  46.    $rows3[] = array(
  47.       'id' => $row['id'],
  48.       'id_elemento' => $row['id_elemento'],
  49.       'nome' => $row['nome'],
  50.       'prezzo' => $row['prezzo'],
  51.       );
  52.  }
  53.  
  54.  echo "<pre>";
  55.  print_r($rows) . "<br />" . print_r($rows2) . "<br />" . print_r($rows3);
  56.  echo "</pre>";
  57.  
  58.  //echo "<pre>" . json_encode($rows) . "</pre>";
  59.  mysqli_free_result($result);
  60.  mysqli_free_result($result2);
  61.  mysqli_free_result($result3);
  62.  
  63.  //$file = fopen('results.json', 'w+');
  64.  //fwrite($file, json_encode($rows1));
  65.  //fclose($file);
  66.  
  67.  mysqli_close($conn);
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement