Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "project_db";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. // Check connection
  10. if ($conn->connect_error)
  11. {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. $sql = "SELECT ingredient_id, ingredient_name FROM ingredients";
  16. $result = $conn->query($sql);
  17.  
  18. $array = array(); //used to hold each ingredient as a variable to pass to php script
  19. array_unshift($array,"");
  20. unset($array[0]); //our first ingredient_id is set to 1 so I've started my array at 1 to allow for that
  21. $_SESSION['arr'] = $array;
  22.  
  23. if ($result->num_rows > 0)
  24. {
  25. // output data of each row
  26. while($row = $result->fetch_assoc())
  27. {
  28. echo "<br /><button id='$row[ingredient_id]' name='button' value='button' class='btn-info btn-lg' onClick='return addItem($row[ingredient_id])'>$row[ingredient_name]</button><br />";
  29. array_push($_SESSION['arr'],$row['ingredient_name']);
  30. }
  31. }
  32. else
  33. {
  34. echo "0 results";
  35. }
  36.  
  37. $conn->close();
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement