My question clearly states it in the heading, anyway a more elaborate question is how can I randomly show a variable (eg. name) from a mysql database using php with a dbo connection in xampp environment.
Here is what I've come up with from scratch:-
<?php
$db = new PDO
('mysql:dbname=lab1;host=localhost;charset=utf8','root',
'');
$stmt = $db->prepare('SELECT * FROM countries');
?>
<head>
<meta charset="UTF-8"/>
<p>RANDOM!</p>
</head>
<body>
<?php
$stmt -> execute();
foreach($stmt as $row){
$something = array ($row['name'] . $row['name']);
}
$rand_keys = array_rand($something, 1);
echo $something[$rand_keys[0]] . "\n";
?>
</body>
Seems to not work when I try opening it (from localhost)