Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2. $host="XXX"; //replace with database hostname
  3. $username="YYY"; //replace with database username
  4. $password="ZZZ"; //replace with database password
  5. $db_name="ZZZ"; //replace with database name
  6.  
  7. $ageFrom = $_GET['ageSearchFrom'];
  8. $ageTo = $_GET['ageSearchTo'];
  9.  
  10. $con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. $sql = "SELECT * FROM users WHERE age BETWEEN '$ageFrom' AND '$ageTo'";
  14.  
  15. $result = mysql_query($sql);
  16. $json = array();
  17.  
  18. if(mysql_num_rows($result)){
  19. while($row=mysql_fetch_assoc($result)){
  20. $json['user'][]=$row;
  21. }
  22. }
  23. mysql_close($con);
  24. echo json_encode($json);
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement