php - mysqli multiple where clause for two different variables -
i have users current latitude , longitude saved variables $latitude
, $longitude
. want data database echo out if latitude , longitude matches users current latitude , longitude.
$con=mysqli_connect("localhost","db_username","password","db_dbname"); $stmt = $con->prepare('select * test geoloc1 = ? , geoloc2 = ?'); $stmt->bind_param('ss', $latitude, $longitude); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { ?> <div class="latlon"> <a><?php echo $row['geoloc1'] ?></a> </div> <?php } ?>
yet im getting error fatal error: call undefined method mysqli_stmt::get_result()
, can't seem solve why coming up!
just quit unusable mysqli , use pdo, has 2 advantages: in neat , works.
$dsn = "mysql:host=localhost;dbname=db_dbname;charset=utf8"; $opt = array( pdo::attr_errmode => pdo::errmode_exception, pdo::attr_default_fetch_mode => pdo::fetch_assoc ); $con = new pdo($dsn, "db_username","password", $opt); $stmt = $con->prepare('select * test geoloc1 = ? , geoloc2 = ?'); $stmt->execute(array($latitude, $longitude)); $data = $stmt->fetchall(); foreach ($data $row) { ?> <div class="latlon"> <a><?php echo $row['geoloc1'] ?></a> </div> <?php } ?>