I am using PHP to connect to a MySql DB that is getting the whole database and the table rows look like this insert into users (id, first_name, last_name, email, country) values (1, 'Imojean', 'Nunnery', 'inunnery0@webeden.co.uk', 'Sweden');
and I want to only get the rows that have certain countries. I only want to grab the rows that have "United States", "Japan", "France", etc... How do I go about doing that? This is how I am connecting to my DB and bringing it in via PHP while using Vue JS on the front end.
PHP
<?php
$host = "localhost";
$user = "root";
$password = "root";
$dbname = "someDB";
$con = mysqli_connect($host, $user, $password,$dbname);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
<?php
include "config.php";
$condition = "1";
if(isset($_GET['userid'])){
$userid = mysqli_real_escape_string($con,trim($_GET['userid']));
$condition = " id=".mysqli_real_escape_string($con,$_GET['userid']);
}
$userData = mysqli_query($con,"select * from users WHERE ".$condition );
$response = array();
while($row = mysqli_fetch_assoc($userData)){
$response[] = $row;
}
echo json_encode($response);
exit;
HTML/Vue
<script>
var app = new Vue({
el: '#app',
data: {
users: "",
userid: 0
},
methods: {
allRecords: function(){
axios.get('config.php')
.then(function (response) {
app.users = response.data;
})
.catch(function (error) {
console.log(error);
});
},
recordByID: function(){
if(this.userid > 0){
axios.get('config.php', {
params: {
userid: this.userid
}
})
.then(function (response) {
app.users = response.data;
})
.catch(function (error) {
console.log(error);
});
}
}
}
});
</script>