Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $dbpassword = "root";
  6. $dbname = "personal_data";
  7.  
  8.  
  9. $conn = new mysqli($servername, $username, $dbpassword, $dbname);
  10.  
  11. if (mysqli_connect_errno()) {
  12. printf("Connect failed: %sn", mysqli_connect_error());
  13. exit();
  14. }
  15.  
  16. $email = mysqli_real_escape_string($conn, $_POST['email1']);
  17.  
  18. $getUserID = "SELECT UserID FROM personal_data WHERE Email='$email' LIMIT 1";
  19. $resultUserID = mysqli_query($conn, $getUserID);
  20. $valueUserID = mysqli_fetch_array($resultUserID, MYSQLI_ASSOC);
  21. $UserID = $valueUserID["UserID"]; //get user ID
  22.  
  23. $getItemsInDB = "SELECT BarcodeID FROM intermediate_database WHERE UserID='$UserID'";
  24. $resultItems = mysqli_query($conn, $getItemsInDB);
  25. $valueItems = mysqli_fetch_array($resultItems, MYSQLI_ASSOC);
  26. //use ID to get all barcode values
  27.  
  28. $itemArray = array();
  29. foreach($valueItems as $item) { //iterate over array of barcodes
  30. //get each item's full line in product_database
  31. $getBarcodeID = "SELECT BarcodeID, BrandName, ProductName, Weight FROM product_database WHERE UserID='$item'";
  32. $resultBarcodeID = mysqli_query($conn, $getBarcodeID);
  33. $valueBarcodeID = mysqli_fetch_array($resultBarcodeID, MYSQLI_ASSOC);
  34.  
  35. array_push($itemArray, $valueBarcodeID);
  36. //return array below in json_encode & access in js
  37. }
  38.  
  39. json_encode($itemArray);
  40.  
  41. //how do I iterate over the $valueItems array and send to product_databse and then save retreived data in another array and then send that data to js file for printing
  42.  
  43.  
  44. echo json_encode(array("UserID" => $valueUserID["UserID"], "items" => $itemArray));
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement