Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: text/plain');
  4.  
  5. $servername = "mysql.cba.pl";
  6. $username = "1312Chef1312";
  7. $password = "chefff1312";
  8. $dbname = "chef_cba_pl";
  9.  
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17. $type = $_GET['type'];
  18. $receptureName = $_GET['receptureName'];
  19.  
  20. $sql = "SELECT * FROM $type WHERE nazwaPotrawy = '$receptureName'";
  21. $result = $conn->query($sql);
  22.  
  23. echo "{\n" . $type . ":[ \n";
  24.  
  25. $i = 0;
  26. if ($result->num_rows > 0) {
  27. // output data of each row
  28. while($row = $result->fetch_assoc()) {
  29. $i++;
  30. if($i < $result->num_rows) {
  31. echo "\t" . (json_encode($row) . ",\n");
  32. }
  33. else {
  34. echo "\t" . (json_encode($row) . "\n");
  35. }
  36. //$rows[] = $row;
  37. }
  38. }
  39. echo ']}';
  40. //echo json_encode($rows);
  41.  
  42. $conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement