try {
$dbh = new PDO('mysql:host=localhost;dbname=wqposts', 'root', '');
$query = "SELECT wqpid FROM threads WHERE posted ='0'";
$randomids = '';
foreach ($dbh->query($query) AS $row) {
$randomids[] .= $row['wqpid'];
}
} catch (PDOException $exception) {
echo "Connection error: " . $exception->getMessage();
}
$post = array_rand($randomids, 1);
try {
$dbh = new PDO('mysql:host=localhost;dbname=wqposts', 'root', '');
$stmt = $dbh->prepare("SELECT * FROM threads WHERE wqpid = :wqpid");
$stmt->bindParam(':wqpid', $post, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch()) {
//output html
}
Somehow WHERE posted ='0' in the first statement isn't working because results in the second statement where posted = 1 are showing.
If I run select * from threads where posted=0; in mysql I see 400-500 results which is correct. In case it's needed posted is tinyint with length of 1.
$randomids[] .= $row['wqpid'];, but the[]means that you are appending a value onto an array, so you just turned $randomids into an array, after initializing it as an empty string. Then, you use the operator.=which is a string concatenator. I have no idea what the end result of that is, but I don't think it's what you're trying to do.