I'm trying to insert a failsafe into a code to prevent them from going a step further, and I've been scratching my head for a while now. I am able to put something into an array, but I am not able to get the items from the array to match the second select query. I only get Array instead of the value from the item.
My first select query is this:
$datohenter3 = "select DATE_FORMAT(datotid, '%Y.%m.%d') AS dato from gramorapport34 group by dato order by dato asc";
$hentdatoer = $db->query($datohenter3);
$periodedatoer = array();
for ($x = 1; $x <= $db->affected_rows; $x++) {
$periodedatoer[] = $hentdatoer->fetch_assoc();
}
Then I want to match the values from this array with my next select query:
$rapportdatoer = "select fradato, tildato from gramorapportlogg WHERE fradato IN('".$periodedatoer."') OR tildato IN('".$periodedatoer."')";
$rapportdatoeksist = $db->query($rapportdatoer);
if ( !$rapporteksist ) die('Database Error: '.$db->error);
while($row = mysqli_fetch_array($rapportdatoeksist))
{
print_r($row);
}
The errors I am getting are:
Notice: Array to string conversion for the second select
Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' fradato IN('Array') OR tildato IN('Array')' at line 1
I'm not an expert in JOIN SELECT queries. This is using MariaDB 10.3.12 with PHP7.2
var_dump available at: https://www.lokalradio.no/rapport/gramo/datohenttest.php